005
15.08.2005, 13:18 Uhr
CRocker
|
Hallo, habe im c++ Code nun folgendes gemacht. Der Aufruf der Funktion scheint nun zu funktionieren, allerdings möchte ich jetzt noch per array die Motorpositionen zur VB-DLL schicken. Könnt Ihr mir da helfen.
c++ Quelltext Header: (move axis ist der Befehl in meiner VB DLL )
typedef int (CALLBACK *move_axis)(int*, int*,int*,int*); move_axis m_pmove_axis;//Verweis mit pointer aus den Aufruf der Funktion
HINSTANCE m_hinstMotorControlDll; //hinstance einer Member zuweisen
cpp: Lade so meine DLL mit Meldung ob gefunden
m_hinstMotorControlDll = ::LoadLibrary("D:_Motorcontrol.dll"); if (m_hinstMotorControlDll != 0) AfxMessageBox("Motorcontrol DLL geladen!\n", MB_ICONINFORMATION); else AfxMessageBox("Motorcontrol.dll\nkonnte nicht geladen werden !!!\n", MB_ICONSTOP);
if (m_hinstMotorControlDll) m_pmove_axis = (move_axis)::GetProcAddress(m_hinstMotorControlDll, "move_axis"); --------------------------------------------------------------------------------------
Auszug aus meiner VB-DLL: Public Structure Motorposition Dim axisnr As Integer //Achsennummer (4 vorhanden) Dim units As Integer // Einheit Dim setval As Double //Fahrwert der Achsen
Public Function move_axis(ByVal motor_excom_channel As Integer, ByVal position() As Motor_Pos_Setval) As Array Dim funcreply(UBound(position)) As Motor_Action_Reply Dim indat As SO_External_Communication.portcom.portin_data Dim comm As Communication.portcom Dim portreply, lastindex, i Dim sb2, sb1, sb0 As Byte Dim xtarget, motstep Dim zwopi As Double zwopi = 8 * System.Math.Atan(1) ' Calculate the value of pi.
lastindex = UBound(position) For i = 0 To lastindex With position(i) motstep = motor_parameter(.axisnr).steps_per_motor_rev * motor_parameter(.axisnr).stepdivider Select Case .units Case .unit_deg xtarget = .setval / 360 * motstep * motor_parameter(.axisnr).gear_ratio Case .unit_rad xtarget = .setval / zwopi * motstep * motor_parameter(.axisnr).gear_ratio Case .unit_step xtarget = .setval Case .unit_mm xtarget = .setval * motstep / motor_parameter(.axisnr).spindle_pitch Case .unit_µm xtarget = .setval * 1000 * motstep / motor_parameter(.axisnr).spindle_pitch End Select End With
sb2 = Fix(xtarget / 65536) sb1 = Fix((xtarget - sb2 * 65536) / 256) sb0 = Val(xtarget) - sb1 * 256 - sb2 * 65536
On Error GoTo errorhandler portreply = comm.send_byte(motor_excom_channel, 5) portreply = comm.send_byte(motor_excom_channel, position(i).axisnr) portreply = comm.send_byte(motor_excom_channel, sb2) portreply = comm.send_byte(motor_excom_channel, sb1) portreply = comm.send_byte(motor_excom_channel, sb0)
indat = comm.wait_port_reply(2, 20) If indat.errorcode = 0 Then funcreply(i).errorcode = 0 funcreply(i).errordescription = "Operation successfull" Else funcreply(i).errorcode = indat.errorcode funcreply(i).errordescription = "Timeout" End If funcreply(i).axisnr = position(i).axisnr Next i move_axis = funcreply Exit Function End Function --------------------------------------------------------------------------------------
Wie kann ich nun mit dem Funktionsaufruf auch werte übermitteln und auf Antwort meiner Hardeware warten??? |