10-12-2019 12:52 AM
hi,
I am reading and writing to a serial port of pc.
objective is to
1- continuously poll or read the port until i get a specific combination of 6 bytes HEX
2- if the said combination is true write a specific 6 byte frame so that host can know that link is established (this should execute once i guess).
3- again poll for next combination of frame of HEX byte so that i can send a profile say sine wave to host pc(serial port ) upon his request and to 6229 PCI card in target pc so that it can also generate predefined counts to a stepper motor.
4- is it possible to do all above in real-time with desktop pc
5- can we read counter pulses using digital in channel which are being out from CTR0 channel
regards,
Solved! Go to Solution.
10-12-2019
02:53 AM
- last edited on
07-18-2024
03:12 PM
by
Content Cleaner
Is there a reason you're constrained to using Serial ports? There are probably easier ways to communicate between two desktop computers (for example, Network Streams, which uses TCP).
Regarding your questions,
4: should be possible. By real-time, I'm assuming you mean at a human speed without noticeable delay.
5: If you mean can you set up a Digital Input task and connect it to the terminal used for the output of a Counter Out task, then yes, this should be possible.
10-12-2019 08:32 AM
ok Sir, thanks but
how about 1 ,2 , 3 what could be best logic? and VI design
10-12-2019 09:01 AM
To do something continuously, use a While loop.
To check if something matches a pattern, use the "=" node from the Comparison palette.
Make sure that you consider the case where it isn't an integer multiple of your pattern length, e.g. if I'm searching for "12345" and I read a pattern like:
1236921895312512345231892...
then I need to ensure I don't do the following (pattern length is 5):
12369 - 21895 - 31251 - 23452 - 31892...
so I'd need to scroll one character at a time instead.
Repeat for the other patterns you want. Consider the use of subVIs to encapsulate reuse code (i.e. bits that you do more than once).
10-12-2019 09:13 AM
@cbutcher wrote:
To do something continuously, use a While loop.
To check if something matches a pattern, use the "=" node from the Comparison palette.
Make sure that you consider the case where it isn't an integer multiple of your pattern length, e.g. if I'm searching for "12345" and I read a pattern like:
1236921895312512345231892...
then I need to ensure I don't do the following (pattern length is 5):
12369 - 21895 - 31251 - 23452 - 31892...
so I'd need to scroll one character at a time instead.
Repeat for the other patterns you want. Consider the use of subVIs to encapsulate reuse code (i.e. bits that you do more than once).
yes but i need to execute code once if a link is established for some pattern and check sum.
the next time to avoid the read vi can we use "First call "function so that it does not go and search again for first part
10-12-2019
09:40 AM
- last edited on
07-18-2024
03:13 PM
by
Content Cleaner
Use of either a State Machine would probably solve your problems in that regard.
You could also just have two While loops (first to check connection, then to check for subsequent patterns).
From your description (which may not give enough information to allow an accurate suggestion, but I'll go ahead anyway), I'd suggest writing a VI that receives a new character, and keeps a record of the previous N characters, where N is determined based on the length of a pattern it is given as an input. You can make this preallocated reentrant to allow use of uninitialized Shift Registers.
10-14-2019 07:47 AM
I'm also of the opinion that you will be much better off using a TCP connection than a serial port. Based on the application you are describing (streaming a signal), the Network Stream would be ideal. It would make this application A LOT simpler (Connect Endpoints, write all of the data, Close Endpoints).
But if you insist on keeping the serial port communications, you need a good, robust communication protocol. If going the binary/hex/raw route, you need a start character (0x02 is normal, Start of Text is the ASCII definition, STX) followed by some message identification byte, followed by the data and a checksum. The number of bytes to read should be determined by the message ID. So the reader can just read 1 byte until the 0x2 is read. Then it reads the next byte and then the rest of the message based on that ID byte. Then compare the checksum to verify the transmission was correct. If correct, process the message. If incorrect, throw it away. Regardless, go back to looking for the STX. So your establish connection could consist of a simple 3 byte message and wait for an acknowledge response (again, 3 bytes should do). One that has happened, you have a connection and you can send the more complicated messages that include your data.