LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

serial port read and write : executing link establish once

Solved!
Go to solution

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.

  • at the same time i should poll to read next request to generate triangular wave and send it to host pc on same serial port and 6229 card (installed in target) to generate a set of pulses to move some degree for 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,

0 Kudos
Message 1 of 7
(2,349 Views)

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.


GCentral
Message 2 of 7
(2,322 Views)

ok Sir, thanks but 

how about 1 ,2 , 3 what could be best logic? and VI design

0 Kudos
Message 3 of 7
(2,292 Views)

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).


GCentral
Message 4 of 7
(2,286 Views)

@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

0 Kudos
Message 5 of 7
(2,282 Views)
Solution
Accepted by topic author DMic

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.


GCentral
Message 6 of 7
(2,278 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 7 of 7
(2,214 Views)