Hello Everyone,
I am having some problems with VB using MSComm. I have some hardware I developed and the firmware instructs the MCU to send data via serial port to a PC.
The data stream must not stop, and for one reason or another I can't send data to the MCU requesting data. In essence, I have an asynchronous system where data is sent in from the hardware to the PC like so: PXXXXX,YYYYYY, ZZZZZZCRLF. The "P" is just a preamble so I know when the data is fetched from VB I know the start of the frame.
Now the issue I have is that sometimes, some of the YYYY parameters get mixed as XX,YYY, and so on. I friend told me we can run two threads, one thread can just have MSComm in a loop constantly polling the port. If the bytes come in store them into a buffer cue. The main window, would fetch this buffer cue, and parse the incoming data.
I read the VB6 does not permit passing data via global variables from one thread to the other. I have also heard from other friends that it is possible to crack the permission in an apartment thread, and be able to pass data from one to the other!
Has anyone done this?
Again the problem in a summary:
1. ASCII Data is being sent from hardware continuously, in this form PXXXXX,YYYYYY,ZZZZZCRLF (Carriage Return LineFeed). The number of bytes are variable sometimes it sends 10, sometimes it sends up to 30.
2. I want to fetch that stream parse it and send it on its way to a graph. Often times I see data outliers due to numbers concatenated from either previous data, or wrong parsing. Somehow I get outliers... and that causes data corruption. I know it is the way MSComm is reading the data. I logged 7 hrs with Tera Term Pro and I didn't get these errors.
Has anyone one faced this dilemma? How to synch an asynchronous data link? I thought of creating another window (Frame2 in Vb) and launch the window, have a timer that interrupts every 1msec and polls the port, but I think this is just a mickey mouse patch, and it may cause other issues in the code which I don't know about. I figure if I have a thread running in the background whose job is just to fetch data and save it to a cue that would work out nicely.
If you know how, please let me know.