Results 1 to 4 of 4

Thread: how do i send info to com1/com2 ?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Posts
    3

    Question

    I need to send data to a POS display in vb. How do i do something like this ?

    Please help

    Kind Regards,
    spaceknop

  2. #2
    New Member
    Join Date
    May 2000
    Location
    Auburn,AL
    Posts
    12
    If you are trying to output data to a com port, you can use the MSComm object, which needs to be checked in the Project/Components menu to be added to objects menu. Set up the CommPort property of MSComm to the desired Com port of your system. You can then use

    MSComm.Output = "string"

    to send information through the specified port.

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Lightbulb MSComm Control

    Do you mean sending instruction or command to POS (Pint Of Sales)?
    If yes, then just continue read this...
    I think you need to know the others device Comm Port parameter frist, then follow by open your PC commport and use the
    MComm1.Output = <Your Instruction>

    below is the sample code for sending and receiving data by using serial comm port.

    Code:
    'Code under basic Form (Main Form)
    Option Explicit
    Dim ZZ$
    Private Sub CmdAction_Click(Index As Integer)
    Select Case Index
    Case 0 'Send
        MSComm1.InBufferCount = 0
        MSComm1.Output = txtSend.Text
        txtRx.Text = txtRx.Text & "<Tx> " & txtSend.Text & vbCrLf
        txtRx.SelStart = Len(txtRx)
    Case 1 'Setting
        Load frmSetting
        frmSetting.Show
    End Select
    End Sub
    
    Private Sub Form_Load()
    SaveSetting "xCOM", "Parameter", "ComPort", MSComm1.CommPort
    SaveSetting "xCOM", "Parameter", "Settings", MSComm1.Settings
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If MSComm1.PortOpen Then MSComm1.PortOpen = False
    Dim xForm As Form
    For Each xForm In Forms
        Unload xForm
    Next
    End Sub
    
    Private Sub MSComm1_OnComm()
    Select Case MSComm1.CommEvent
    Case comEvReceive
        txtRx.Text = txtRx.Text & "<Rx> " & MSComm1.Input & vbCrLf
        txtRx.SelStart = Len(txtRx)
    End Select
    
    End Sub
    
    'Code under Basic Form (Com Port properties)
    Option Explicit
    Private xComSetting(3) As String
    Private Sub CmdAction_Click()
    On Error GoTo Open_Err
    SaveSetting "xCOM", "Parameter", "ComPort", Mid(Trim(Combo1.Text), 4, 1)
    SaveSetting "xCOM", "Parameter", "Settings", Trim(Combo2.Text) & Chr(44) & Trim(Combo3.Text) & Chr(44) & Trim(Combo4.Text) & Chr(44) & Trim(Combo5.Text)
    
    frmMain.MSComm1.CommPort = CInt(GetSetting("xCOM", "Parameter", "ComPort", 1))
    frmMain.MSComm1.Settings = GetSetting("xCOM", "Parameter", "Settings", "9600,n,8,1")
    frmMain.MSComm1.PortOpen = True
    frmMain.CmdAction(0).Enabled = True
    frmMain.Shape1.FillColor = vbGreen
    Unload Me
    
    Exit Sub
    Open_Err:
    MsgBox "(" & Err.Number & ") " & Err.Description, vbExclamation + vbOKOnly, "RS232"
    frmMain.Shape1.FillColor = vbRed
    If frmMain.MSComm1.PortOpen Then frmMain.MSComm1.PortOpen = False
    End Sub
    
    Private Sub Form_Load()
    Dim xArray, xParse
    Dim xCnt%
    If frmMain.MSComm1.PortOpen Then frmMain.MSComm1.PortOpen = False
    frmMain.Shape1.FillColor = vbRed
    frmMain.CmdAction(0).Enabled = False
    xCnt = 0
    Combo1.ListIndex = CInt(GetSetting("xCOM", "Parameter", "ComPort", 1)) - 1
    xArray = Split(GetSetting("xCOM", "Parameter", "Settings", "9600,n,8,1"), Chr(44), -1)
    For Each xParse In xArray
        xComSetting(xCnt) = xParse
        xCnt = xCnt + 1
    Next
    Select Case xComSetting(0)
    Case "1200"
        xCnt = 0
    Case "2400"
        xCnt = 1
    Case "4800"
        xCnt = 2
    Case "9600"
        xCnt = 3
    Case "14400"
        xCnt = 4
    Case "28800"
        xCnt = 5
    Case "33600"
        xCnt = 6
    Case "55600"
        xCnt = 7
    End Select
    Combo2.ListIndex = xCnt
    
    Select Case xComSetting(1)
    Case "n"
        xCnt = 0
    Case "e"
        xCnt = 1
    Case "o"
        xCnt = 2
    Case "m"
        xCnt = 3
    Case "s"
        xCnt = 4
    End Select
    Combo3.ListIndex = xCnt
    
    Select Case xComSetting(2)
    Case "6"
        xCnt = 0
    Case "7"
        xCnt = 1
    Case "8"
        xCnt = 2
    End Select
    Combo4.ListIndex = xCnt
    
    Select Case xComSetting(3)
    Case "1"
        xCnt = 0
    Case "1.5"
        xCnt = 1
    Case "2"
        xCnt = 2
    End Select
    Combo5.ListIndex = xCnt
    End Sub

  4. #4
    Guest
    And another method:

    Code:
        Dim iCOM1 As Integer
        iCOM1 = FreeFile
        Open "COM1" For Output As #iCOM1
        Print #iCOM1, "DATA"
        Close #iCOM1

Posting Permissions

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



Click Here to Expand Forum to Full Width