Dear All,
We are programming a small application that sends a string to the Serial Port, we are forced to send a string and some values of the string are chr(0).
For input we found the solution by reading "bytes" using "ReadSerialPortData(COMID, @bBuffer, 1)" ... is there any solution for sending a string?
Thanks in advance,
String with Chr(0)
String with Chr(0)
Last edited by mcsalsa on Tue Dec 10, 2013 9:42 am, edited 1 time in total.
-
- Addict
- Posts: 1519
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: String with Chr(0)
As a buffer, use an array rather than a string.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: String with Chr(0)
The array idea is good, alternatives would be allocated memory or a fixedstring (which can contain 0 bytes).
BERESHEIT
Re: String with Chr(0)
Thank you very much!! I will try it and let you know.
Re: String with Chr(0)
The answer is simple:
Bernd
Code: Select all
WriteSerialPortData()
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: String with Chr(0)
If you have to cheat to get it to work, you can substitute Chr(0) with another character, so long as the receiving app (is there a receiving app?) can decipher.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: String with Chr(0)
You cannot have a string in PB where 'some' values = Chr(0). PB strings end at Chr(0). Build your output string in a buffer and write data just as you are reading data.mcsalsa wrote:We are programming a small application that sends a string to the Serial Port, we are forced to send a string and some values of the string are chr(0).
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: String with Chr(0)
Not entirely true. You can build a string inside a fixed length string, but you cannot use build in string commands, as they all terminate on the chr(0) character.skywalk wrote:You cannot have a string in PB where 'some' values = Chr(0). PB strings end at Chr(0). Build your output string in a buffer and write data just as you are reading data.mcsalsa wrote:We are programming a small application that sends a string to the Serial Port, we are forced to send a string and some values of the string are chr(0).
But yes, if effect, using regular string commands you cannot create anything containing a chr(0).
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
-
- Enthusiast
- Posts: 542
- Joined: Tue Apr 24, 2012 5:08 pm
- Location: Ontario, Canada
Re: String with Chr(0)
The lack of OLE string support has been the single biggest problem in our conversion from PowerBasic to PB.blueznl wrote:But yes, if effect, using regular string commands you cannot create anything containing a chr(0).
In the real world, Chr(0) exists as a real character in most data sent to, and received from, devices. Manipulating such data is a non-issue with OLE strings.
Unfortunately, PB memory and string support is tied too closely to null-terminated strings. So after spending several hundred man-hours trying to build our own OLE-style string support into PB, I finally decided that we should do what we did for file I/O support -- use the powerful OLE features that already exist in PowerBasic and FreeBasic.
We're now in the process of creating a series of macros to link to OLE code in the two dynamic libraries we originally set up for file I/O -- a PowerBasic "support.dll" for Windows, and a FreeBasic "support.so" for Linux.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
~ Spike Milligan