Thanks VEL448
I now have the following declarations:
[code]Declare Function OpenDevice Lib “K8074.dll” _
(ByVal portName As String) As Integer
Declare Sub EmergencyStop Lib "K8074.dll" _
(ByVal deviceId As Integer)
Declare Sub SendCommand Lib "K8074.dll" _
(ByVal deviceId As Integer, ByVal address As Byte, ByVal cmd As Byte, ByVal param As Byte)
Declare Function DisplayAddress Lib "K8074.dll" _
(ByVal deviceId As Integer) As Integer
Declare Sub SetRelay Lib "K8074.dll" _
(ByVal deviceId As Integer, ByVal address As Byte, ByVal relayid As Integer)
Declare Sub ClearRelay Lib "K8074.dll" _
(ByVal deviceId As Integer, ByVal address As Byte, ByVal relayid As Integer)
Declare Sub ToggleRelay Lib "K8074.dll" _
(ByVal deviceId As Integer, ByVal address As Byte, ByVal relayid As Integer)
Declare Sub SetAddress Lib "K8074.dll" _
(ByVal deviceId As Integer, ByVal oldAddress As Byte, ByVal newAddress As Byte)
Declare Sub ForceAddressReset Lib "K8074.dll" _
(ByVal deviceId As Integer)
Declare Sub SendByte Lib "K8074.dll" _
(ByVal deviceId As Integer, ByVal address As Byte, ByVal bitmask As Byte)
Declare Sub CloseDevice Lib "K8074.dll" _
(ByVal deviceId As Integer)
Declare Sub GetDllVersion Lib "K8074.dll" ()[/code]
Now I can connect to the K8074 successfully, read it’s address, change it’s address and close the device, but the only way i can get it to switch the VM119 relay on or off is by using:
SendCommand(m_device, m_address, CByte(80), 49)
which I have adapted from the VS.NET demo project for the K8074. The code is inside a timer which is enabled on the button mousedown and disabled on the button mouseup Here’s the code from the vs.net demo:
private void TimerMom_Tick(object sender, EventArgs e)
{
K8074Native.SendCommand(m_device, (Byte)(cbAddress.SelectedIndex + 1), 0x50, (Byte)(48+m_MomIdx));
}
SetRelay, ToggleRelay, ClearRelay and EmergencyStop do not seem to have any effect, either in my code OR in the demo project.
In the K8074 API guide PDF, hex values for the CMD parameter of SendCommand are listed as:
[quote]
#define K8074_SET_ADDRESS 0x41 // ‘A’
#define K8074_SEND_BYTE 0x42 // ‘B’
#define K8074_CLEAR_RELAY 0x43 // ‘C’
#define K8074_DISPLAY_ADDRESS 0x44 // ‘D’
#define K8074_EMERGENCY_STOP 0x45 // ‘E’
#define K8074_FORCE_RESET 0x46 // ‘F’
#define K8074_SET_RELAY 0x53 // ‘S’
#define K8074_TOGGLE_RELAY 0x54 // ‘T’ [/quote]
in my adapted code, CByte(80) represents as hex 0x50 (or &h50 in vb.net) yet this value is not listed as a value in the above list - Is it an undocumented command?
Also, why in the PDF document does it say:
yet in my working code the param value is 49?
Is this problem something to do with controlling the VM119 as opposed to the 8 channel relay board? I have tried putting SetRelay and ClearRelay inside timers but that doesn’t work
On another related note, the document www.vellemanprojects.com/downloads/0/us … _k8074.pdf
is possibly corrupt as i have not been able to open it with any viewer.
Apologies for the long post!
Al