lngStatus = CommFlush(intPortID)
intPortID = Forms!frmLogin!txtFinComPort.value
' Initialize Communications
lngStatus = CommOpen(intPortID, "COM" & CStr(intPortID), "baud=115200 parity=N data=8 stop=1")
If lngStatus <> 0 Then
' Handle error.
lngStatus = CommGetError(strError)
MsgBox "COM Error: " & strError
Application.Quit
End If
' Set modem control lines.
lngStatus = CommSetLine(intPortID, LINE_RTS, True)
lngStatus = CommSetLine(intPortID, LINE_DTR, True)
' Write data to serial port.
' Build data packet to transmit (passing command code, and data to package)
strData = BuildData(JsonConverter.ConvertToJson(transaction, Whitespace:=3))
' Send the data packet and check for error
lngStatus = CommWrite(intPortID, strData)
If lngStatus <> Len(strData) Then
' Handle error.
On Error Resume Next
End If
Pause (5)
If lngStatus < 0 Then
'Handle error
lngStatus = CommGetError(strError)
MsgBox "COM Error: " & strError
End If
' Read maximum of 2034 bytes from serial port.
lngStatus = CommRead(intPortID, strData, 2036)
If lngStatus <> Len(strData) Then
'Handle error
On Error Resume Next
ElseIf lngStatus < 0 Then
' Handle error.
On Error Resume Next
End If
Set rs = db.OpenRecordset("tblEfdReceipts", dbOpenDynaset, dbSeeChanges)
'Processing data from the string above
Set db = CurrentDb
Set json = JsonConverter.ParseJson(Chr(91) & Mid(strData, 8) & Chr(34) & "}" & Chr(93))
'Process data.
Z = 1
For Each Details In json
rs.AddNew
rs![EsDTime] = CDate(Format$(Details("ESDTime"), "00/00/00 00:00:00"))
rs![TerminalID] = Details("TerminalID")
rs![InvoiceCode] = Details("InvoiceCode")
rs![InvoiceNumber] = Details("InvoiceNumber")
rs![FiscalCode] = Details("FiscalCode")
rs![INVID] = Me.InvoiceID
rs.Update
Z = 1 + 1
Next
rs.Close
Set rs = Nothing
Set db = Nothing
Set json = Nothing
Set transaction = Nothing
Set transactions = Nothing
Set item = Nothing
Set items = Nothing
Set Tax = Nothing
Set fld = Nothing
Set root = Nothing
' Reset modem control lines.
lngStatus = CommSetLine(intPortID, LINE_RTS, False)
lngStatus = CommSetLine(intPortID, LINE_DTR, False)
' Close communications.
Call CommClose(intPortID)
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.