Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

send string with serialoutblock


kokihualpa Mar 25, 2020 04:31 PM

Hi there

I know that you can use serialinblock() and serialoutblock() when you want to handle binary numbers. I mean 00111011 for example. But what would happen if you send string variables?.

Can I declare binary variable in public?

if you use serialopen in format 3.


Sam Apr 11, 2020 06:10 PM

SerialInBlock will bring in bytes from the serial buffer and copy them directly into the destination without interpretation.

SerialOutBlock will output the bytes contained in the source without interpretation.

The following example assigns the value of lng1, lng2, and lng3 using decimal, hexadecimal, and binary notation, respectively. The values used in the assignments are equivalent to the four characters "1234".

It also shows the use of arrays and the mixing of different formats / notations. The values used are equivalent to the eight characters "12345678".

It then uses SerialOutBlock to output the 4 and 8 bytes contained the variables declared.

Public lng1 As Long = 825373492
Public lng2 As Long = &h31323334
Public lng3 As Long = &b00110001001100100011001100110100
Public str1 As String = "1234"
Public lng4(2) As Long = {825373492,892745528}
Public lng5(2) As Long = {&b00110001001100100011001100110100,&h35363738}
Public str2 As String = "12345678"

BeginProg

  SerialOpen (ComC1,115200,3,0,50)
  Scan (5,Sec,0,0)
    
    SerialOutBlock (ComC1,lng1,4)
    SerialOutBlock (ComC1,lng2,4)
    SerialOutBlock (ComC1,lng3,4)
    SerialOutBlock (ComC1,str1,4)

    SerialOutBlock (ComC1,lng4,8)
    SerialOutBlock (ComC1,lng5,8)
    SerialOutBlock (ComC1,str2,8)

  NextScan
EndProg

 

If you monitor the output from ComC1 using the terminal you'll see,

 

CR1000X>W

1: ComRS232
2: ComME
3: Com310
4: ComSDC7
5: ComSDC8
6: Com320
7: ComSDC10
8: ComSDC11
9: ComC1
10: ComC3
11: ComC5
12: ComC7
13: ComUSB
15: TCP/IP
16: SDM-SIO4
17: Ethernet
22: USB network
23: IP Trace
32..47: SDM-SIO1
Select: 9

 ASCII (Y)? N

 opening 9

 hit ESC to exit, any other key to renew timeout
18:08:55.000 T 31 32 33 34                                      1234
18:08:55.001 T 31 32 33 34                                      1234
18:08:55.002 T 31 32 33 34                                      1234
18:08:55.003 T 31 32 33 34                                      1234
18:08:55.004 T 31 32 33 34 35 36 37 38                          12345678
18:08:55.005 T 31 32 33 34 35 36 37 38                          12345678
18:08:55.006 T 31 32 33 34 35 36 37 38                          12345678

 

Log in or register to post/reply in the forum.