Attribute VB_Name = "SerialSend"
Option Explicit

'----------------------------------------------------------
'  Function     : CommSend
'  Return value : None
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub CommSend(ByVal PJIndex As Integer)

    On Error Resume Next
    
    Dim LogData As String
    Dim CommNo As Integer
    
    If (LanForm.MSComm(PJIndex).PortOpen = False) Then
        With LanForm.MSComm(PJIndex)
            .CommPort = PJInfo(PJIndex).Connection.Serial.PortNo
            .Settings = PJInfo(PJIndex).Connection.Serial.Settings
            .InputMode = comInputModeBinary
            .NullDiscard = False
            .InputLen = 0
            .RThreshold = 1
        End With
        LanForm.MSComm(PJIndex).PortOpen = True
        If Err Then
            Exit Sub
        End If
    End If
    
    Queue(PJIndex, QueueRP(PJIndex)).Status = QS_GO
    LanForm.MSComm(PJIndex).Output = Queue(PJIndex, QueueRP(PJIndex)).SendData
    LogData = "Comm-Send(" & CStr(PJIndex) & "):" & CharConvertB(Queue(PJIndex, QueueRP(PJIndex)).SendData, CInt(Queue(PJIndex, QueueRP(PJIndex)).SendDataLen))
    Call LogFileWrite(LogData)
    LanForm.TimeoutTimer(PJIndex).Interval = CommTimeoutTime
    LanForm.TimeoutTimer(PJIndex).Enabled = True
    
End Sub
