SERIN2, SEROUT2 with long variables


Closed Thread
Results 1 to 1 of 1
  1. #1
    Join Date
    Sep 2009
    Posts
    737

    Default SERIN2, SEROUT2 with long variables

    First time using long variables, so I need little clarification...
    When I used word variables, I used this code to receive it:
    Code:
    CNT1 VAR WORD
    PC_in:
    SERIN2 Rx,84,3000,PC_in,[WAIT("DATA:"), CNT.byte1,CNT1.byte0]
    'And to display it:
    SEROUT2 Tx,84,["CNT1:",DEC5 CNT1,10,13]
    In VB6 code for extracting bytes from word and to send:
    Code:
    Private Sub Command1_Click()
    Dim Str As String, B1 As Byte, B2 As Byte
    Dim CNT As Long, C1 As long
    
    CNT = CLng(TxtCNT.Text)
    C1 = 256
    B2 = Br \ C1
    B1 = Br - C1 * B2
    Str = "DATA:" & Chr(B2) & Chr(B1)
    MsComm1.Output=Str
    End Sub
    Now I tried same with word variables:
    PBP:
    Code:
    CNT VAR LONG
    PC_in:
    SERIN2 Rx,84,3000,PC_in,[WAIT("DATA:"), CNT.BYTE3, CNT1.BYTE2, CNT1.BYTE1, CNT1.BYTE0]
    SEROUT2 Tx,84,["CNT1:",DEC9 CNT1,10]
    VB:
    Code:
    Dim Str As String, B1 As Byte, B2 As Byte, B3 As Byte, B4 As Byte,
    Dim CNT As Long, C1 As Long, C2 As Long, C3 As Long, C4 As Long
    
    CNT = CLng(TxtCNT.Text)
    C1 = 16777216
    C2 = 65536
    C3 = 256
    B4 = CNT \ C1
    CNT = CNT - B4 * C1
    B3 = CNT \ C2
    CNT = CNT - B3 * C2
    B2 = CNT \ C3
    B1 = CNT - C3 * B2
    Str = "DATA:" & B4 & B3 & B2 & B1
    MsComm1.Output=Str
    End Sub
    But doesn't work.
    VB extracted and sent bytes correctly.
    But for example when I sent number 400401402, I receive 842215986.
    Does anyone know why this happens and how to correct that?
    EDIT:
    Now I see mistake
    Maybe it's time to rest a little
    VB obviously not sending correctly, It should be
    Code:
    Str = "DATA:" & Chr(B4) & Chr(B3) & Chr(B2) & Chr(B1)
    Excuse me for harassment.
    Last edited by pedja089; - 18th November 2010 at 23:29.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts