Page 1 of 1
String with Chr(0)
Posted: Tue Dec 10, 2013 9:37 am
by mcsalsa
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,
Re: String with Chr(0)
Posted: Tue Dec 10, 2013 9:41 am
by User_Russian
As a buffer, use an array rather than a string.
Re: String with Chr(0)
Posted: Tue Dec 10, 2013 9:55 am
by netmaestro
The array idea is good, alternatives would be allocated memory or a fixedstring (which can contain 0 bytes).
Re: String with Chr(0)
Posted: Tue Dec 10, 2013 12:09 pm
by mcsalsa
Thank you very much!! I will try it and let you know.
Re: String with Chr(0)
Posted: Tue Dec 10, 2013 1:53 pm
by infratec
The answer is simple:
Bernd
Re: String with Chr(0)
Posted: Tue Dec 10, 2013 4:45 pm
by IdeasVacuum
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.
Re: String with Chr(0)
Posted: Tue Dec 10, 2013 5:03 pm
by skywalk
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).
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.
Re: String with Chr(0)
Posted: Mon Dec 16, 2013 8:54 am
by blueznl
skywalk wrote: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).
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.
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.
But yes, if effect, using regular string commands you cannot create anything containing a chr(0).
Re: String with Chr(0)
Posted: Mon Dec 16, 2013 3:56 pm
by BorisTheOld
blueznl wrote:But yes, if effect, using regular string commands you cannot create anything containing a chr(0).
The lack of OLE string support has been the single biggest problem in our conversion from PowerBasic to PB.
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.