Hi
I have build some industrial devices over the past years, and they all made use of PIC 16F876, with standard RS232 comms to the PC software running at 19200 baud. The software was created in Visual Basic 3 & 5. Devices are used in the plant, and are connected to a laptop PC. The sofware comms is relatively simple, with the following data formats:
Synch Byte (&hFF), followed by a command byte, and several data bytes depending on the command.
With the new laptops, serial ports are no longer available, and in the new designs, I want to make use of the USB Serial function in Flowcode to get rid of the USB to Serial cable. The circuit design is very easy to convert from RS232 to USB (removing the MAX232 chip, solder on 3 USB wires, and replace the 16F with 18F2550).
Setting up the USB Serial port was no problem, and the USB Serial is working correct. However, my biggest problem is the fact that I am unable to determine between a received &hFF data, and no data received. I had a look at changing the Synch Byte in the VB code, but this will solve only the Synch side of the comms. Some of the data sent to the devices can include &hFF as well.
I have no problems sending &h00 to &hFF from the USB to the PC.
Is there a method to be able to determine if the USB Serial return value of &hFF was due to data received, or no data received?
Thanks in advance.
USB Serial - Receiving '&hFF' in Flowcode 4
Moderator: Benj
- Eric Brouwer
- Posts: 20
- Joined: Sat Oct 30, 2010 10:17 am
- Has thanked: 3 times
- Been thanked: 11 times
- Contact:
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
- Contact:
Re: USB Serial - Receiving '&hFF' in Flowcode 4
Hi,
When I'm using my PC to send data to the microcontroller, I usually convert the byte to send into an ascii string.
A byte of value 0x5F will send a string "5F" to the PIC. (of course I use a startbyte and stopbyte to know where to start reading and when to stop)
I don't know if this could help you...
BR,
Nicolas L. F.
When I'm using my PC to send data to the microcontroller, I usually convert the byte to send into an ascii string.
A byte of value 0x5F will send a string "5F" to the PIC. (of course I use a startbyte and stopbyte to know where to start reading and when to stop)
I don't know if this could help you...
BR,
Nicolas L. F.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: USB Serial - Receiving '&hFF' in Flowcode 4
Hello,
I have modded the component code slightly so that the receive byte macro now returns the value 256 for a timeout and 255 is valid data. Note that you will have to change your receive variable to type INT so you can check for invalid data.
Copy the attached C file into your Flowcode v4/Components directory before starting Flowcode to allow the changes to be loaded.
I have modded the component code slightly so that the receive byte macro now returns the value 256 for a timeout and 255 is valid data. Note that you will have to change your receive variable to type INT so you can check for invalid data.
Copy the attached C file into your Flowcode v4/Components directory before starting Flowcode to allow the changes to be loaded.
- Attachments
-
- PIC_USBSerial.c
- (10.14 KiB) Downloaded 364 times
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Eric Brouwer
- Posts: 20
- Joined: Sat Oct 30, 2010 10:17 am
- Has thanked: 3 times
- Been thanked: 11 times
- Contact:
Re: USB Serial - Receiving '&hFF' in Flowcode 4
Thank you very much for your fast responce, and the solution to my problem. I really appreciate it. I just love the USB components, and have tried every one of them with great success in Visual Basic 6.
I have tried another work-around, using Timer2. Start timer before checking for received data. After data received, check if timer2 rolled over. If it did roll over, &hFF indicated no data received. If not, &hFF data received. I was still tweaking the code and clock speed, but now it's no longer required.
I have tried another work-around, using Timer2. Start timer before checking for received data. After data received, check if timer2 rolled over. If it did roll over, &hFF indicated no data received. If not, &hFF data received. I was still tweaking the code and clock speed, but now it's no longer required.
- Eric Brouwer
- Posts: 20
- Joined: Sat Oct 30, 2010 10:17 am
- Has thanked: 3 times
- Been thanked: 11 times
- Contact:
Re: USB Serial - Receiving '&hFF' in Flowcode 4
Hi Benj
Just to report back. I have tested the USB Serial with the new code, and it works great.
Just to report back. I have tested the USB Serial with the new code, and it works great.
- Attachments
-
- USB_Serial_Demo_Byte.fcf
- USB Serial receiving &h00..&hFF
- (10.5 KiB) Downloaded 328 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: USB Serial - Receiving '&hFF' in Flowcode 4
Great glad its working ok, cheers for letting me know
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel