Hello Guest it is September 19, 2019, 05:11:58 AM

Author Topic: MacroPump and RS232 with CreateObject get Coinitialization ERROR  (Read 4518 times)

0 Members and 1 Guest are viewing this topic.

I'm a new user.

I've tested a macro that use the Serial Port to comunicate with my remote panel build up around a PIC18F4620 by Microchip.
To do this I've used :
   Set objCOM = CreateObject ("MSCOMMLib.MSComm", "MSCommEvent_")

Everything works fine until I save it as MacroPump.m1s. At this point I get always an error "Coninitialization".

After same test I thing I've found out these:

1.If in MacroPump.m1s there is any kind of CreateObject this error  comes out alwasy.
2.If I put the source in a macro like M101.m1s and then I call it by MacroPump.m1s then everythings looks to work well but I cannot run any other macro.
3.If I use the calls to the API to comunicate with the serial port and I put everything into the macropump.m1s that it looks to work fine but to use the API is little more complex then createobject.
4.If I use SendFifo/GetFifoEntry the RS232 has to much delaysometimes and something like Jog/buttons doesn't work fine.

Someone can help me about this COINITIALIZATION ERROR in MacroPump?
Sorry for my poor english.

This is my Source Code MACROPUMP.M1S:

Option Explicit
Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
Dim objCOM As Object
Dim RS232_ResponseOK As Boolean
Dim vbCrLf As String
Dim RS232_Response_Command As String
Dim RS232_Response_Char As String
Dim Loop_Exit As Boolean



Sub Main ()
   Message "Remote Panel..."

   Call COM_Open
   
   Call COM_Out_Line("L0101Remote Panel")
   Call COM_Clean
   Call COM_Out_Line("S0")
   
   Loop_Exit=False
   RS232_Response_Char=""
   RS232_Response_Command=""
   Message "Remote Panel Start at " & Now
   Do
      If Loop_Exit Then Exit Do
      If objCOM.InBufferCount>0 Then
      'Dati in arrivo
         RS232_Response_Char=objCOM.Input
         RS232_Response_Command=RS232_Response_Command  & RS232_Response_Char
      Else
         Sleep 10
         RS232_Response_Char=""
      End If
      If RS232_Response_Char=Chr(10) Then
      'Comando da Elaborare
         Message RS232_Response_Command
         Call PANEL_Command_Parse (RS232_Response_Command)
         RS232_Response_Command=""
      End If
   Loop
   
   Call COM_Out_Line("O1=0")
   
   Message "End " & Now
   Call DoOEMButton(334)
End Sub


Sub PANEL_Command_Parse(Comandi As String)
'*** Elaborazione Comandi inviati da REMOTE PANEL

   Dim Comando As String
   Dim ParComando As String
   
   Do
      If Len(Comandi)=0 Then Exit Do
      'Pulisci caratteri non attesi
      Do
         Comando=Mid(Comandi,1,1)
         If Asc(Comando)>=65 And Asc(Comando)<=90 Then Exit Do
         If Len(Comando)>1 Then
            Comando=Mid(Comando,2)
         Else
            Comando=""
            Exit Do
         End If
      Loop
      If Comando<>"" Then
      'Comando Presente
         ParComando=Mid(Comandi,2,3)
         If Len(ParComando)=3 Then
            Call PANEL_Command_Exec (Comando,ParComando)
         End If
         Comandi=Mid(Comandi,5)
      Else
         Comandi=""
      End If
   Loop
End Sub


Sub PANEL_Command_Exec(Comando As String,ParComando As String)
'*** Esegui comando inviato da Panelli Remoto
   Dim NInput as Integer
   Dim SInput as Integer
   Select Case Comando
      Case "B"
         Select Case ParComando
             'X+
             Case "010"
                Call DoOEMButton(334)
             Case "011"
                Call DoOEMButton(307)
             'X-
             Case "020"
                Call DoOEMButton(334)
             Case "021"
                Call DoOEMButton(308)
     
             'Y+
             Case "040"
                Call DoOEMButton(335)
             Case "041"
                Call DoOEMButton(309)
             'Y-
             Case "050"
                Call DoOEMButton(335)
             Case "051"
                Call DoOEMButton(310)
     
             Case "031","030"
                Loop_Exit=TRUE                             
         End Select
         
      Case "I"
      'Input
         NInput=CINt(Mid(ParComando,1,2))
         SInput=CINt(Mid(ParComando,3,1))
         Call SetUserLED (1100+NInput, SInput)
         
                       
      Case Else
   End Select
End Sub


Sub COM_Open
   'Apertura COM
   Set objCOM = CreateObject ("MSCOMMLib.MSComm", "MSCommEvent_")
   'Set objCOM = WScript.CreateObject ("MSCOMMLib.MSComm", "MSCommEvent_")
   objCOM.CommPort = 1
   If Not(objCOM.PortOpen) Then
      objCOM.InputLen = 1                   
      objCOM.InputMode = 0
      objCOM.RThreshold = 0 ' Non viene generato l'evento                   
      objCOM.Handshaking=2
      'objCOM.RTSEnable=True
      objCOM.NullDiscard=True
      objCOM.InBufferSize=10000
      objCOM.OutBufferSize=10000
      objCOM.Settings = "57600,n,8,1"
      objCOM.PortOpen = True
      vbCrLf = Chr(10) & Chr(13)
   End If
End Sub


Sub COM_Close
   If objCOM.PortOpen Then
      objCOM.PortOpen = False
   End If
End Sub


Sub COM_Out_Wait
   Dim RS232_WaitMaxTime As Integer
   'Attendi inviao Completo
   RS232_WaitMaxTime = 2 'Secondi
   RS232_ResponseOK = False
   SetTimer(1)
   Do
      If objCOM.OutBufferCount=0 Then
         RS232_ResponseOK = False
         Exit Do
      End If
      If GetTimer(1) >= RS232_WaitMaxTime Then Exit Do
      Sleep 10
   Loop

End Sub 
 
Sub COM_Clean
   Dim RS232_IN_Tmp AS String
   Do
      Sleep 10
      If objCOM.InBufferCount>0 Then
      'Dati in arrivo
         RS232_IN_Tmp=objCOM.Input
      Else
         Exit Do
      End If
   Loop
End Sub

Sub COM_Out_Line(Testo As String)
   objCOM.Output =Testo & Chr(10) & Chr(13)
   Call COM_Out_Wait
End Sub
Re: MacroPump and RS232 with CreateObject get Coinitialization ERROR
« Reply #1 on: July 12, 2007, 09:23:07 PM »
I am sorry to say that I don't think you can do that in the Macro pump :( it is code that gets run once an update not all the time... The stuff that you are looking to do would be best done in C++

Thanks
Brian
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com
Re: MacroPump and RS232 with CreateObject get Coinitialization ERROR
« Reply #2 on: July 13, 2007, 02:54:42 AM »
Hi.
With the last update 2.3 there is not anymore the problem about the error with CreateObject in the MacroPump.
I've done some test and it looks to work well also at 115200 baud.
As soon as possible we will test this remote panel on a milling machine and we will find out what kind of problem we will get.

Bye
Gianfranco Fazzini