Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Serial Port - Cattlerustler method problem and Kernel32 method problem

Author
Message
Ben_UK78
13
Years of Service
User Offline
Joined: 10th Jul 2010
Location:
Posted: 5th Jul 2011 22:52
I am trying to get data from the serial port. So far I have tried using Kernel32 and the Cattlerustler plugin.

The data I am receiving comes in the form of a channel number (i.e 01) followed by a record number (i.e 11) followed by a value of unknown length

I tried the kernel32 method from the windows library first using code like this:


The problem is that the data on the serial port is of an unknown length. That code requires me to set the length (in the example the length is set arbitrarily at 600).

I don't think I can use that method without knowing the number of characters of data waiting to be picked up.

2. That is a pain since it is my preferred method. I found that if I grab the result from that kernel32 method and save the string to a txt file all the carriage returns between the records and channels are respected and I keep all the data structure - i.e I don't have to write a function to try and work out the length of the data between the channel and record numbers.

3. So becuase that didn't work I opted to try Cattlerustlers plugin.

Using this, and not knowing the amount of data on the port I opted to to read each character and add it to a string then look for the start of file and end of file markers (&& and !! respectively). I then wrote the code to work out the position of all the channels and records relative to their sequence in the data.

The very big problem is that the data I read from the port occasionally has missing characters.

I set it up like so:


I cannot use this method if I am reasonably regularly (like on in every 60 characters) missing one. When it occurs in the channel and record section I have no way of knowing where the data starts and stops between them.

Anyway, my request is this - please can anyone help with either method.

I need help either with the code in DB to read how many characters are ready to be retrieved using Kernel32 and "readfile", or help with what I am doing wrong in setting up the port. Cattlerustlers plugin allows the timeouts to be set as well as the receive threshold, read buffer size etc.

On the sending system the only options are baud, databits, parity and stopbits. The flow control on the sending system is set to hardware.

Thats all I have, and i've been on it now for 2 days solid. My project has hit a brick wall until I solve this puppy.

Much thanks for any help.
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 6th Jul 2011 01:34
COM ports are notoriously a pain in the backside.

I tried a few different things last year and ended up using the Kernel32 method. I'm not going to be of much help though, because the best I was able to achieve was the reception of a single byte in between 100ms timeouts. The whole thing I was trying to do barely worked, but it was enough.

I can't imagine actually trying to transfer large amounts of data with it. You'll need a better written plug-in for it. I tried to understand CattleRustler's plug-in, but didn't get the hang of it.

WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 6th Jul 2011 04:19 Edited at: 6th Jul 2011 04:22
If I remember properly, setting the handshake mode on actually makes data transfer a lot more faster and reliable because the hardware deals with the handshaking and the software only has to worry about the data packets.

You should also be able to terminate the transfer manually by sending your own escape sequence, ie 0xfffefdfc, something that wouldn't be sent over the line.

You can also send a single data packet for the lot, send the size first and the rest of the packet is the actual data.

On some serial ports you can automatically read the baud rate and the hardware adjusts is for you. I'm also thinking this is to do with handshake syncing too.

Warning! May contain Nuts!
mr_d
DBPro Tool Maker
17
Years of Service
User Offline
Joined: 26th Mar 2007
Location: Somewhere In Australia
Posted: 6th Jul 2011 09:23
Quote: "The problem is that the data on the serial port is of an unknown length. That code requires me to set the length (in the example the length is set arbitrarily at 600).

I don't think I can use that method without knowing the number of characters of data waiting to be picked up."

Quote: "Using this, and not knowing the amount of data on the port I opted to to read each character and add it to a string then look for the start of file and end of file markers (&& and !! respectively). I then wrote the code to work out the position of all the channels and records relative to their sequence in the data."

Sorry if I misunderstand you in the above statements, but couldn't you use Kernel32 method combined with your Cattlerustlers method if you just specify 1 byte to read each call of Kernel32?
I know that this is not optimal (and I would just read blocks of maybe 1K each call and then parse the result myself to seperate the fields you want).

sladeiw
14
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 7th Jul 2011 22:53
I was using the CattleRustler plugin and had exactly the same problem with missing characters. I'm reading a barcode scanner and different types of code have different lengths, plus allowing for errors etc means I can't wait for an exact number of characters. It could be the timeouts, you did redact that part from your example. I set MAXDWORD for ReadIntervalTimeout which just returns what is already received in the buffer immediately. They you can construct your own string and split it with the markers.

Quote: "ReadIntervalTimeout
A value of MAXDWORD, combined with zero values for both the ReadTotalTimeoutConstant and ReadTotalTimeoutMultiplier members, specifies that the read operation is to return immediately with the bytes that have already been received, even if no bytes have been received.
"


http://msdn.microsoft.com/en-us/library/aa363190%28v=VS.85%29.aspx

Login to post a reply

Server time is: 2024-04-19 06:43:32
Your offset time is: 2024-04-19 06:43:32