Private Sub MSComm1_OnComm() Select Case MSComm1.CommEvent Case comEvReceive ' Received RThreshold # of chars. Rxbuff() = MSComm1.Input Call HandleReceivedData End Select End Sub ' --------------------------------------------------------------------- ' called at comms kickoff Sub InitialiseComms() frmPlcComms.MSComm1.CommPort = ComPort frmPlcComms.MSComm1.Settings = "9600,E,7,1" frmPlcComms.MSComm1.PortOpen = True frmPlcComms.MSComm1.DTREnable = True frmPlcComms.MSComm1.RTSEnable = True frmPlcComms.MSComm1.InputMode = comInputModeBinary frmPlcComms.MSComm1.InputLen = 0 'Forces entire buffer read End Sub
Private Sub Command1_Click() On Error GoTo errHandler 'FOR WRITING MSComm1.CommPort = 2 MSComm1.Settings = "9600,N,8,1" MSComm1.PortOpen = True MSComm1.Output = "Hey its working" 'Text1.Text MsgBox MSComm1.OutBufferCount MSComm1.PortOpen = False 'FOR READING MSComm1.CommPort = 2 MSComm1.Settings = "9600,N,8,1" MSComm1.PortOpen = True MsgBox MSComm1.InBufferCount MSComm1.InputMode = comInputModeText 'Text1.Text = MSComm1.Input MsgBox MSComm1.Input MSComm1.PortOpen = False errHandler: If Err.Number <> 0 Then MsgBox "Error No: " & Err.Number & ", Error Description: " & Err.Description End If End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionOption Explicit Private Sub Form_Load() Show Text3.SetFocus Timer1.Enabled = False Check1.Caption = "Input Barcode" End Sub Private Sub Check1_Click() Timer1.Enabled = True Timer1.Interval = 10 If Check1.Value = 1 Then Text1.Enabled = False 'Disable Text1&2 while Text2.Enabled = False 'Barcode reader is reading. Else Text1.Enabled = True Text2.Enabled = True End If End Sub Private Sub Text3_Change() If Check1.Value 0 Then Text3.Text "" 'Don't accept any input. End Sub Private Sub Timer1_Timer() If Check1.Value = 1 Then Text3.SetFocus Text3.Text = "" Timer1.Enabled = False End Sub
Private Sub CmdDone_Click() If Not Timer1 Then If MSComm1.PortOpen = True Then MSComm1.PortOpen = False End If Done = True Code$ = FrmScanSerial.TxtInput.Text Unload Me End If End Sub Private Sub CmdScan_Click() Dim started On Error GoTo Errorhandler started = False DoEvents Timer1.Enabled = True Instring$ = "" TxtInput.Text = "" Done = False If MSComm1.PortOpen = False Then MSComm1.PortOpen = True End If lblaction.Caption = "WAITING FOR SCAN" Instring$ = "" Do While Not Done DoEvents Do While MSComm1.InBufferCount > 0 started = True DoEvents Instring$ = Instring$ & MSComm1.Input Timer2.Interval = 100 Timer2.Enabled = True Do While Timer2.Enabled = True DoEvents Loop Loop If MSComm1.InBufferCount 0 And started True Then Done = True End If Loop TxtInput.Text = Instring$ Timer1.Enabled = False If MSComm1.PortOpen = True Then MSComm1.PortOpen = False End If lblaction = Len(Instring$) Exit Sub Errorhandler: If Err = 8005 Then MsgBox ("Port Already Open - Change Settings and Select a Different Port Number") Exit Sub End If If Err = 8002 Then MsgBox ("Invalid Port Number - Change Settings and Select a Different Port Number") Exit Sub End If End Sub Private Sub CmdSettings_Click() Dim Settings$, Port$ Dim OldSettings$ OldSettings$ = MSComm1.Settings On Error GoTo Errorhandler Settings$ = InputBox("Enter New Settings", , MSComm1.Settings) MSComm1.Settings = Settings$ Port$ = InputBox("Enter Serial Port Number", , MSComm1.CommPort) MSComm1.CommPort = Port$ Open App.Path & "\Port.ini" For Output As #1 Print #1, Port$ Close #1 Exit Sub Errorhandler: If Err = 380 Then MsgBox ("Invalid Value") MSComm1.Settings = OldSettings Resume Next Else MsgBox (Error) End If End Sub Private Sub Form_Load() Dim Outport$ On Error GoTo Errorhandler Open App.Path & "\Port.ini" For Input As #1 Input #1, Outport$ Close #1 MSComm1.CommPort = Outport$ Exit Sub Errorhandler: If Err 55 Or Err 53 Then Open App.Path & "\Port.Ini" For Output As #1 Print #1, "1" Close #1 Outport$ = "1" MSComm1.CommPort = "1" End If End Sub Private Sub Timer1_Timer() Timer1.Enabled = False End Sub Private Sub Timer2_Timer() Timer2.Enabled = False End Sub
Private Sub Command1_Click() Dim i As Integer Dim hdib As Long Dim n As Integer Dim z As Integer ' Change this to your value: n = 2 Call TWAIN_LogFile(1) Call TWAIN_SetHideUI(1) Call TWAIN_SetJpegQuality(75) If BARCODE_IsAvailable = 0 Then MsgBox "Barcode Function Not Available" End If If TWAIN_OpenDefaultSource() <> 0 Then Call TWAIN_SelectFeeder(1) Call TWAIN_EnableDuplex(1) ' Not guaranteed to work, check return = 1: Call TWAIN_SetPixelType(2) Call TWAIN_SetLightPath(0) Call TWAIN_SetXferCount(n) If TWAIN_SetAutoScan(0) = 0 Then MsgBox "SetAutoScan(FALSE) failed - scanner cannot single-scan?" End If Call TWAIN_SetMultiTransfer(1) If TWAIN_BeginMultipageFile("c:\image.pdf") = 0 Then For i = 1 To n ' If you can't use Me.hwnd, pass 0: hdib = TWAIN_Acquire(Me.hwnd) If hdib = 0 Then Exit For End If ' <your image processing here> ' Get int of the barocde that is recognized z = BARCODE_Recognize(hdib, 1, -1) If z > 0 Then [b]' this is the part I am having trouble with. I'm don't know how to use this function MsgBox BARCODE_GetText(z, "")/b End If Call TWAIN_DibWritePage(hdib) Call DIB_Free(hdib) Next i Call TWAIN_EndMultipageFile End If Call TWAIN_CloseSource End If If TWAIN_LastErrorCode() <> 0 Then Call TWAIN_ReportLastError("Unable to scan.") End If End Sub
Si l'on ouvre un banal bloc notes, on lui met le focus et on scanne un code, le chiffre apparait comme par magie