8 Replies - 1425 Views - Last Post: 27 April 2013 - 06:14 AM Rate Topic: -----

#1 Halfmens  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 25-July 11

Project runs uncompiled but not compiled

Posted 24 April 2013 - 01:30 PM

An odd error occurs after a Visual Basic 6 (SP6) project has been compiled.
In the UNCOMPILED version of the project everything works 100%, no errors
In the compiled (.exe) version the data in the database can be accessed, a relay board is activated (the dll is correctly called) and then the software seems to be unable to access the DLL controlling the DC motor controller.
This only happens in the Compiled version of the VB6 project.

Document attached

Any suggestion to solve this problem are highly appreciated.

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Project runs uncompiled but not compiled

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,796
  • Joined: 26-March 09

Re: Project runs uncompiled but not compiled

Posted 24 April 2013 - 02:08 PM

Do you get any errors at all?

Can you explain what's in the attached document? I know many of the people on here, including me, don't download attachments, so if possible, post any relevant information directly. Thanks.
Was This Post Helpful? 1
  • +
  • -

#3 Halfmens  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 25-July 11

Re: Project runs uncompiled but not compiled

Posted 24 April 2013 - 11:41 PM

View Postmaj3091, on 24 April 2013 - 10:08 PM, said:

Do you get any errors at all?

Can you explain what's in the attached document? I know many of the people on here, including me, don't download attachments, so if possible, post any relevant information directly. Thanks.


The only error generated in the compiled version is "-2"
This error tells me the required board is not found. In the code on this line the speed setting of motor 2 should be executed, however, as the code can't find the required board nothing can happen.
'Zet motorsnelheid
Boardnumber = 1
Error = CM_Motor_M2Speed(Boardnumber, Speed2, Inputs)
DoEvents
'FoutMelding
If Error <> 0 Then
strTekst = "Foutmelding: " & Error & " M2 Speed frmMeetPoduct"
MsgBox strTekst, vbOKOnly + vbCritical, "ATH Development"
End If

As mentioned before this error does noet occur in the uncompiled code, if the code is ran within Visual Basic 6 all code is executed as expected.



Content of document attached:
An odd error occurs after a Visual Basic 6 (SP6) project has been compiled.
In the UNCOMPILED version of the project everything works 100%, no errors
In the compiled (.exe) version the data in the database can be accessed, a relay board is activated (the dll is correctly called) and then the software seems to be unable to access the DLL controlling the DC motor controller.
This only happens in the Compiled version of the VB6 project.

Any suggestion to solve this problem are highly appreciated.





[Private Sub BerekenLaserSlijpMachine()
'Elke encoder stap is de waarde van strSlijpMeetbankEncoderFactor
'Verwerk de positie naar "van links naar rechts"
'sngLaserPositie = Hoeveelheid van de eerstvolgende stap in mm
sngLaserPositie = sngStappen(sngRecordNummer - 1) - sngStappen(sngRecordNummer)
'lngEncoderEindPositie is waarnaar de motor moet bewegen in encoder pulsen
'lngEncodereindPositie wordt vervangen met oorspronkelijke waarde + de waarde van de eerstvolgende stap in encoder pulsen
'sngLaserPositie wordt eerst omgezet in microns
sngLaserPositie = Int(sngLaserPositie * 1000)
lngEncoderEindPositie = lngEncoderEindPositie + (sngLaserPositie * Val(strSlijpMeetbankEncoderFactor))
If lngEncoderEindPositie < 0 Then
lngEncoderEindPositie = lngEncoderEindPositie * -1
End If
'Trial re-init
Boardnumber = 1
BoardType = CM_GetBoardType(Boardnumber)
If BoardType = 5 Then
Else
txtFoutmelding.Visible = True
strFoutmelding = strFoutmelding + " " + Str(BoardType) + " , " + Str(Teller) + " Geen verbinding met de USB poort. Sluit programma af en start opnieuw"
txtFoutmelding.BackColor = QBColor(12)
txtFoutmelding.Text = strFoutmelding
DoEvents
Stop
End If
DoEvents
If Error <> 0 Then
strTekst = "Foutmelding: " & Error & " Init does not work"
MsgBox strTekst, vbOKOnly + vbCritical, "ATH Development"
End If

'Richting waarde = 2 voor voorwaarts
Boardnumber = 1
Direction = 2
Speed2 = intMotorSnelheid
'Zet motorsnelheid
Boardnumber = 1
Error = CM_Motor_M2Speed(Boardnumber, Speed2, Inputs)
DoEvents
'FoutMelding
If Error <> 0 Then
strTekst = "Foutmelding: " & Error & " M2 Speed frmMeetPoduct"
MsgBox strTekst, vbOKOnly + vbCritical, "ATH Development"
End If
Waarde = CM_Motor_M2Direction(Boardnumber, Direction, Inputs)
'FoutMelding
If Waarde <> 0 Then
strTekst = "Foutmelding: " & Waarde & " M2 Direction:" & Direction & " frmMeetProduct"
MsgBox strTekst, vbOKOnly + vbCritical, "ATH Development"
End If

Do Until PhidgetEnc.EncoderPosition(0) <= lngEncoderEindPositie * -1
DoEvents
Loop


‘Motor.bas

Declare Function CM_Initialise Lib "mas.dll" () As Integer
Declare Function CM_GetBoardType Lib "mas.dll" (ByVal Boardnumber As Integer) As Integer
Declare Function CM_Motor_M1Speed Lib "mas.dll" (ByVal Boardnumber As Integer, ByVal Speed As Integer, ByRef Inputs As Integer) As Integer
Declare Function CM_Motor_M1Direction Lib "mas.dll" (ByVal Boardnumber As Integer, ByVal Direction As Integer, ByRef Inputs As Integer) As Integer
Declare Function CM_Motor_M2Speed Lib "mas.dll" (ByVal Boardnumber As Integer, ByVal Speed As Integer, ByRef Inputs As Integer) As Integer
Declare Function CM_Motor_M2Direction Lib "mas.dll" (ByVal Boardnumber As Integer, ByVal Direction As Integer, ByRef Inputs As Integer) As Integer
Declare Function CM_Motor_ReadInputs Lib "mas.dll" (ByVal Boardnumber As Integer, ByRef Inputs As Integer) As Integer
Declare Function CM_Motor_GetStatus Lib "mas.dll" (ByVal Boardnumber As Integer, ByRef M1Speed As Integer, ByRef M1Direction As Integer, ByRef M2Speed As Integer, ByRef M2Direction As Integer, ByRef Inputs As Integer) As Integer
Declare Function CM_DIO_Update Lib "mas.dll" (ByVal Boardnumber As Integer, ByVal Outputs As Integer, ByRef Inputs As Integer) As Integer
Declare Function CM_DIO_GetStatus Lib "mas.dll" (ByVal Boardnumber As Integer, ByRefOutputs As Integer) As Integer
Declare Function CM_Relay_Update Lib "mas.dll" (ByVal Boardnumber As Integer, ByVal Outputs As Integer, ByRef Inputs As Integer) As Integer
Declare Function CM_Relay_GetStatus Lib "mas.dll" (ByVal Boardnumber As Integer, ByVal Outputs As Integer) As Integer
Declare Function CM_ANIO_Update1to4 Lib "mas.dll" (ByVal Boardnumber As Integer, ByVal Outputs As Integer, ByRef Results() As Integer) As Integer
Declare Function CM_ANIO_Update5to8 Lib "mas.dll" (ByVal Boardnumber As Integer, ByVal Outputs As Integer, ByRef Inputs As Integer) As Integer
Declare Function CM_ANIO_GetStatus Lib "mas.dll" (ByVal Boardnumber As Integer, ByRef Outputs As Integer, ByRef Sens As Integer) As Integer

Global Const BOARD_MASTER = 0 'Non Isolated Controller
Global Const BOARD_ISOMASTER = 1 'Isolated Controller
Global Const BOARD_DIGITAL_IOSLAVE = 2 'Digital I/O Slave
Global Const BOARD_ANALOGUE_IOSLAVE = 3 'Analogue I/O Slave
Global Const BOARD_RELAY_SLAVE = 4 'Relay Slave
Global Const BOARD_MOTOR_SLAVE = 5 'Motor Slave
Global Const NO_BOARD_DETECTED = 123

'error definities
Global Const SUCCESS = 0 ' geen fouten
Global Const ERR_REQUEST_FAILED = -1 ' algemene fout tijdens uitvoering van commando
Global Const ERR_INVBOARDNUMBER = -2 ' verkeerd Bordnummer aangevraagd of gestuurd
Global Const ERR_NOMASTERFOUND = -3 ' geen master controller gevonden
Global Const ERR_USB_MESSAGING_ERROR = -4 ' onverwacht bericht ontvangen van USB (length or header byte)
Global Const ERR_CHECKSUM = -5 ' checksum error in data ontvangen van slave
Global Const ERR_WRONG_BOARD_TYPE = -6 ' fout commando voor bord type (bv CM_RELAY_Update verzonden met het bord nummer van de Motor Slave)

'Motorbeweging Definities
Global Const MOTOR_STOP = 1 ' stop commando binnen het Direction commando
Global Const MOTOR_FORWARD = 2 ' voorwaarts commando binnen het Direction commando
Global Const MOTOR_REVERSE = 3 ' reverse commando binnen het Direction commando


Global Boardnumber As Integer
Global Inputs As Integer
Global Outputs As Integer
Global Error As Integer
Global BoardType As Integer
Global Speed As Integer
Global Direction As Integer
Global M1Speed As Integer
Global M1Direction As Integer
Global M2Speed As Integer
Global M2Direction As Integer
Global intLaatsteInput As Integer
Global strFoutmelding As String
‘End Motor.bas

‘Relay.bas
Declare Function InitMbee Lib "mb.dll" () As Boolean
Declare Function SetOutputs Lib "mb.dll" (ByVal Outputs As Integer) As Boolean
‘End Relay.bas]
Was This Post Helpful? 0
  • +
  • -

#4 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,796
  • Joined: 26-March 09

Re: Project runs uncompiled but not compiled

Posted 25 April 2013 - 12:46 AM

Without actually knowing your hardware setup and the fact we don't see your full code, I have a couple of questions.

How are you determining the relay board is being activated the first call?

Do you explicitly open the COM port yourself, or is it done through the DLL?

Point I'm trying to get it, is that maybe the board initialises when the COM port is setup, as opposed to the board actually being initialised through the DLL.

The only the other thing you could do, would be to add some debug msgbox statements (or even just a textbox on your form) and write out some pertinent details as you go along....for example, boardtype being returned....is it the correct board type (i.e.: is it failing before trying to control the motor).
Was This Post Helpful? 0
  • +
  • -

#5 Halfmens  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 25-July 11

Re: Project runs uncompiled but not compiled

Posted 25 April 2013 - 02:20 AM

The relay board is a separate board with its own DLL
At the start of the program the several relays are briefly activated and an output signal is send which is picked up by an I/O board which confirms to the program that the relay board is actually responding.

The COM is addressed by DLL only and not by the VB6 code in my program..

First the Master board is initialized.

[Private Sub mnuMaster_Click()

Error = CM_Initialise()

If Error = 0 Then
txtFoutmelding.Visible = False
' lblMaster.Visible = True
mnuSlave.Enabled = True
Else
txtFoutmelding.Visible = True
txtFoutmelding.Text = Error
If Error = -3 Then
txtFoutmelding = "Critische Fout: Geen Masterbord gevonden"
End If
End If

End Sub]

Thereafter a check is made to see if the Motor board is present, which type it is and if it reacts: (the Board number is set by dip switches, changing these settings does not solve the problem.

[Private Sub mnuSlave_Click()

Teller = 1
Boardnumber = 1
BoardType = CM_GetBoardType(Boardnumber)
If BoardType = 5 Then
mnuMeten.Enabled = True
mnuMeten.Visible = True
mnuControle.Visible = False
mnuControle.Enabled = False
mnuSlave.Enabled = False
Else
txtFoutmelding.Visible = True
strFoutmelding = strFoutmelding + " " + Str(BoardType) + " , " + Str(Teller) + " Geen verbinding met de USB poort. Sluit programma af en start opnieuw"
txtFoutmelding.BackColor = QBColor(12)
txtFoutmelding.Text = strFoutmelding
DoEvents
End If
End Sub]

If not an error will be displayed telling the user the board is not found.

In both cases, compiled or uncompiled, no errors are returned during execution.

It is only when the boardnumber again is addressed
[ Boardnumber = 1
Error = CM_Motor_M2Speed(Boardnumber, Speed2, Inputs)]
in the compiled version an error "-2" is generated telling me the boardnumber is not valid anymore.
[Global Const ERR_INVBOARDNUMBER = -2 ]

The odd thing remains why does it work in uncompiled mode but stops working in compiled mode.
Was This Post Helpful? 0
  • +
  • -

#6 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,796
  • Joined: 26-March 09

Re: Project runs uncompiled but not compiled

Posted 25 April 2013 - 03:14 AM

First off, thanks for clarifying a few things. Also, can you please wrap your code in the [code ] tags, it will make it easier to read.

OK, so with the relay board being a different board and having it's own DLL, means we can't use that as an indicator, unless the IO board you refer to also controls your motors?

I'm guessing you're not displaying your whole code here, so again, I'm going to offer some suggestions.

When running in the IDE, it executes slower than the compiled version, so could it be a timing issue?

I notice there is a GetStatus call for the board....maybe you could try calling that to see if it offers any help in regards to the status of the board.

Have you tried taking this back to the bare minimum?? Knock up a small program, that makes the basic calls required (initialise the IO Card, Start/Stop the motor etc.). Test it in the IDE, then try that compiled. If it works, then you're looking elsewhere in your full code. If that doesn't work, you've then got less code to look at for pin-pointing the problem.

I used to work in automation, so I know things like this can be awkward to find, and even more awkward to assist on, without access to the hardware! :)
Was This Post Helpful? 0
  • +
  • -

#7 Halfmens  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 25-July 11

Re: Project runs uncompiled but not compiled

Posted 25 April 2013 - 06:15 AM

Your comment on making a small program for testing triggered something.

I have a system running on the same motor control board (without the relay board) and that runs fine.
I had a quick look at the settings of VB6 in both systems and found the following:

Setting of VB6 on the system that works both in Un- as compiled version

VB6 References:
Visual Basic for Applications
Visual Basic runtime objects and procedures
Visual Basic objects and procedures
OLE Automation
Microsoft DAO 3.6 Object Library
Phidgets Library 2.1 (.oca)
Phidgets Library 2.1 (.dll)

VB6 Components
Microsoft Comm Control 6.0
Phidgets Library 2.1



Setting of VB6 in the system that does not work in the compiled (.exe) version

VB6 References:
Visual Basic for Applications
Visual Basic runtime objects and procedures
Visual Basic objects and procedures
OLE Automation
Microsoft DAO 3.6 Object Library
Phidgets Library 2.1 (.oca)
Phidgets Library 2.1 (.dll)
Microsoft Data Binding Collection VB6.0 (SP4)


VB6 Components
Microsoft ADO Data Control 6.0 (SP6) (OLEDB)
Microsoft Comm Control 6.0
Microsoft Common Dialog Control 6.0 (SP6)
Microsoft Data Grid Control 6.0 (SP3) (OLEDB)
Microsoft Flexgrid Control 6.0 (SP6)
Phidgets Library 2.1

Perhaps you can make some sence out of this.


Private Sub mnuMaster_Click()

    Error = CM_Initialise()

        If Error = 0 Then
            txtFoutmelding.Visible = False
            mnuSlave.Enabled = True
        Else
            txtFoutmelding.Visible = True
            txtFoutmelding.Text = Error
            If Error = -3 Then
                txtFoutmelding = "Critische Fout: Geen Masterbord gevonden"
            End If
        End If

End Sub

Private Sub mnuSlave_Click()

        Teller = 1
            Boardnumber = 1
            BoardType = CM_GetBoardType(Boardnumber)
            If BoardType = 5 Then
                mnuMeten.Enabled = True
                mnuMeten.Visible = True
                mnuControle.Visible = False
                mnuControle.Enabled = False
                mnuSlave.Enabled = False
            Else
                txtFoutmelding.Visible = True
                strFoutmelding = strFoutmelding + " " + Str(BoardType) + " , " + Str(Teller) + "    Geen verbinding met de USB poort. Sluit programma af en start opnieuw"
                txtFoutmelding.BackColor = QBColor(12)
                txtFoutmelding.Text = strFoutmelding
                DoEvents
            End If
End Sub



Private Sub BerekenLaserSlijpMachine()
'Elke encoder stap is de waarde van strSlijpMeetbankEncoderFactor
'Verwerk de positie naar "van links naar rechts"
'sngLaserPositie = Hoeveelheid van de eerstvolgende stap in mm
    sngLaserPositie = sngStappen(sngRecordNummer - 1) - sngStappen(sngRecordNummer)
'lngEncoderEindPositie is waarnaar de motor moet bewegen in encoder pulsen
'lngEncodereindPositie wordt vervangen met oorspronkelijke waarde + de waarde van de eerstvolgende stap in encoder pulsen
'sngLaserPositie wordt eerst omgezet in microns
    sngLaserPositie = Int(sngLaserPositie * 1000)
    lngEncoderEindPositie = lngEncoderEindPositie + (sngLaserPositie * Val(strSlijpMeetbankEncoderFactor))
    If lngEncoderEindPositie < 0 Then
        lngEncoderEindPositie = lngEncoderEindPositie * -1
    End If
'Trial re-init
            Boardnumber = 1
            BoardType = CM_GetBoardType(Boardnumber)
            If BoardType = 5 Then
            Else
                txtFoutmelding.Visible = True
                strFoutmelding = strFoutmelding + " " + Str(BoardType) + " , " + Str(Teller) + "    Geen verbinding met de USB poort. Sluit programma af en start opnieuw"
                txtFoutmelding.BackColor = QBColor(12)
                txtFoutmelding.Text = strFoutmelding
                DoEvents
                Stop
            End If
    DoEvents
     If Error <> 0 Then
    strTekst = "Foutmelding: " & Error & "  Init does not work"
        MsgBox strTekst, vbOKOnly + vbCritical, "ATH Development"
    End If
   
'Richting waarde = 2 voor voorwaarts
    Boardnumber = 1
    Direction = 2
    Speed2 = intMotorSnelheid
'Zet motorsnelheid
    Boardnumber = 1
    Error = CM_Motor_M2Speed(Boardnumber, Speed2, Inputs)
    DoEvents
'FoutMelding
    If Error <> 0 Then
    strTekst = "Foutmelding: " & Error & "  M2 Speed frmMeetPoduct"
        MsgBox strTekst, vbOKOnly + vbCritical, "ATH Development"
    End If
        Waarde = CM_Motor_M2Direction(Boardnumber, Direction, Inputs)
'FoutMelding
    If Waarde <> 0 Then
        strTekst = "Foutmelding: " & Waarde & "  M2 Direction:" & Direction & "  frmMeetProduct"
        MsgBox strTekst, vbOKOnly + vbCritical, "ATH Development"
    End If
        
        Do Until PhidgetEnc.EncoderPosition(0) <= lngEncoderEindPositie * -1
        DoEvents
        Loop
'Achteruit
    Direction = 3
    Waarde = CM_Motor_M2Direction(Boardnumber, Direction, Inputs)
    DoEvents
    If Waarde <> 0 Then
        strTekst = "Foutmelding: " & Waarde & "  M2 Direction:" & Direction & "  frmMeetProduct"
        MsgBox strTekst, vbOKOnly + vbCritical, "ATH Development"
    End If
    Direction = 1
    Waarde = CM_Motor_M2Direction(Boardnumber, Direction, Inputs)
    DoEvents
    If Waarde <> 0 Then
        strTekst = "Foutmelding: " & Waarde & "  M2 Direction:" & Direction & "  frmMeetProduct"
        MsgBox strTekst, vbOKOnly + vbCritical, "ATH Development"
    End If
    txtEncoderPositie.Text = Str(lngEncoderPositie)
    Text2.Text = Str(lngEncoderEindPositie)
    Text1.Text = Str(sngLaserPositie)
    DoEvents
'Sla posities op
    Open "c:\ath_dev\EncoderPositie.csv" For Append As #9
        Print #9, Str(lngEncoderPositie); ";"; Str(lngEncoderEindPositie); ";"; Str(sngLaserPositie); ";"; (Str((Int(lngEncoderPositie / Val(strSlijpMeetbankEncoderFactor)) / 1000)) * -1)
    Close #9

End Sub



This post has been edited by BobRodes: 25 April 2013 - 09:38 PM

Was This Post Helpful? 0
  • +
  • -

#8 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,796
  • Joined: 26-March 09

Re: Project runs uncompiled but not compiled

Posted 25 April 2013 - 07:59 AM

Can you edit your last post and change the closing code tag, the / should be inside the [/ code] (without the spaces, so it appears like below. Thanks.

This is my code


I don't see anything that stands out in the references, besides, that would prevent it working in the uncompiled state.

Do you have the DLL in the same folder as the compiled EXE or in a path that is visible (Windows System for example)?

Where is the sub BerekenLaserSlijpMachine called from? I can't spot it in the code you posted.
Was This Post Helpful? 0
  • +
  • -

#9 Halfmens  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 25-July 11

Re: Project runs uncompiled but not compiled

Posted 27 April 2013 - 06:14 AM

Thanks for your assistance, I have, however, decided to stop the project with these electronics.
It takes to much time and money to investigate the problem, I expect it to be cheaper to change the hardware.
New Motor and Relay control electronics have been ordered from a different supplier, as soon as these items have been delivered I will change the control box and rewrite the software to address the new electronics.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1