Has anybody got any experience of Visual Basic 2008 programming… if so would appreciate a look at some code for working with the USB interface…
Anything you have or can point me at in order to get me started would be great.
Andrew.
Has anybody got any experience of Visual Basic 2008 programming… if so would appreciate a look at some code for working with the USB interface…
Anything you have or can point me at in order to get me started would be great.
Andrew.
Have read this, but can’t get access to review some of the C# files as i only write in Visual Basic.
Am i breaking new ground ?
Andrew
Try using only the assembly file ‘VelbusLib/Velbus/bin/Release/velleman.velbus.dll’. For more details on how to do this, you will need to search around a bit on Google, there is more than plenty of information. Most basic programming handbooks explain this as well.
The only problem can be Visual Studio 2008, which is a newer version than the one that was used to compile the assembly.
Give it a try
I have installed the dll, and get the serial bus item added to the tool bar…that is fine.
I can code the following, but despite what i try and read, anything i put between the brackets gets commented as incorrect syntax. Is there a simple code example to show the right packet syntax. Anything would help.
SerialBusVelbus.PortName = “COM3”
SerialBusVelbus.Send(XXXXXX)
I have been unable to load the VB examples as the use winsock and mscomm ocx files and these are not in the VB2008 version, so the upgrade fails.
I have not been able to show any kind of communication or even test the or capture input from the USB interface.
Can you cut and paste a sample code here from a VB6 example or mail me on andrew@rockhoppers.co.uk.
have also tried to communicate using the Velbus Link program, it says it is connected, but fails to find a push button module and switch module that are installed and connected.
I am building a complete bespoke program, for complete control of the house… and upgrade from a X10 system that is in and running, but can seem to get any further than this. not even got the USB to talk to the PC yet.
It will include, smoke detection, flood detection, alarm system, and a lot more as well as CCTV ability, it is already working on X10, but the X10 system does have limitations.
Did you import the Velleman.Velbus namespace?
Also, you can use the VelbusLink application to intercept or send packets as a test.
You will need to adapt the following C# code to VB.NET:
SerialBus bus = new SerialBus("COM1");
bus.Open();
// Prepare a packet that will switch on the relays
// of a VMB4RY module (see: p.17 of the VMB4RY manual)
Packet packet = new Packet();
packet.Address = 0x02; // change this address to reflect your setup
packet.Priority = PacketPriority.High; // high priority command
packet.DataSize = 2; // 2 data bytes
packet.Command = 0x02; // Command "Switch relay ON"
packet[1] = 0x0F; // We want to switch on all relays
// Issue the command!
bus.SendBlocking(packet);
// Be sure to close the bus so everything
// can be cleaned up properly */
bus.Close();
I will see what I can do to provide a working example in VB.NET 2008
Thanks, yes i did import the namespace.
will try to convert this and see where i get to,
Thanks
Andrew
Ok, making progress, once i get this working i will post for anyone else to use…
what does the “packet[1] = 0x0F;” command do,
this line throws and error on VB 08
Do you have a sample of the code for receiving the packets…in C# is fine i will convert if you do not have in VB 08
Andrew
In VB 08 it rejects;
packet.Address = 0x02
and
packet.Command = 0x02
If i put the text as
packet.Command = “0x02”
it raises an error also.
Maybe i will have to wait till you manage a working example in VB 08
Andrew
Managed to get something to work… sort of !
At least it does not throw an error and the lights on the USB interface flash to show Rx, and the lights on the VMB6IN flash too.
This is where i have got to. not got a relay module yet, so not sure it if it will activate the relay ?
Need a routine to catch the input / response from the USB.
Dim packet As Packet
Me.VelbusSerialBus.PortName = “Com4”
Me.VelbusSerialBus.Open()
If Me.VelbusSerialBus.IsOpen = False Then
MsgBox(“No Serial bus detected…!”)
Exit Sub
End If
packet = New Packet()
packet.Address = System.Convert.ToInt32("b1", 16)
packet.Priority = PacketPriority.High
packet.DataSize = 2
packet.Command = System.Convert.ToInt32("0x02", 16)
VelbusSerialBus.SendBlocking(packet)
VelbusSerialBus.Close()
This means: assign hexadecimal number 2 to the Command member of the packet object. In C# hexadecimal numbers are prefixed with 0x, in VB.NET they are prefixed with &H, for example: &H02, &H0A, …
Not good.
This is what you want
Ok, got that, can you post some sample code for the reception and decoding of packets, and i will have a go at that part now.
Thanks
Andrew
Take a look at the events of the SerialBus component if you want to receive packets
I have had a look a the Velbus dll file and in VB08 it appears to have very few events that would be used to receive packets.
Are you suggesting another instance of a serial bus port, i.e. one to send, (the velbus one) and another one to receive ?
Can you post or mail me a sample code in VB6, this would give me a bit help.
Can the VMB6IN handle NC contacts. i.e. an output from a smoke detector that is NC ?
Andrew
There is an event named PacketReceived which will be triggered each time a packet is received. In Visual Studio you should be able to double-click this event in the property window and all code will be written for you.
Only one instance of the SerialBus component is needed
The DemoAsync demo application uses these events (PacketSent, PacketReceived)
Ok, got some data going now ! Just playing with what the input produces… how to i get the address of the individual button on the VMB6IN, i have set address “B1” and get this from the args.packet.address argument.
Have kept the code very simple till i get it all working !
Andrew
Private Sub VelbusSerialBus_PacketReceived(ByVal source As System.Object, ByVal args As Velleman.Velbus.BusPacketIoEventArgs) Handles VelbusSerialBus.PacketReceived
Dim IncommingData As String
IncommingData = "Start = " & (Hex(args.Packet.STX) + Chr(13))
IncommingData = IncommingData & "Address = " & (Hex(args.Packet.Address) & Chr(13))
IncommingData = IncommingData & "Priority = " & (Hex(args.Packet.Priority) & Chr(13))
IncommingData = IncommingData & "RTR = " & (args.Packet.Rtr) & Chr(13)
IncommingData = IncommingData & "Size = " & (args.Packet.Size) & Chr(13)
IncommingData = IncommingData & "Cmd = " & (args.Packet.Command) & Chr(13)
IncommingData = IncommingData & "ETX = " & (Hex(args.Packet.ETX) & Chr(13))
IncommingData = IncommingData & "Has Cmd = " & (args.Packet.HasCommand)
MsgBox(IncommingData) 'show me the packet
End Sub
A module has an address (=> Packet.Address).
Each VMB6IN module has 6 inputs.
The inputs are usually passed a bit flags in a packet (binary: 00000001 = input 1, 00000010 = input 2, …).
An example:
DATABYTE1 = Packet.Command
DATABYTE2 = First data byte, bitfield to indicate which input you want to get the name from.
So you need to look up which packet you are getting in (Packet.Command) and then find out which byte contains the flags.
Ok, thanks, will see where i get to.
Can the VMB6IN take normally closed connections from motion sensors, or must they be normally open ?
Andrew
Yes, this is not a problem.
The unit will send a ‘button released’ command when the contact opens.
I seem to get two packets, of length 10, delivered for each button press on the VMB6IN module.
The first shows the button ID in the second byte which i can now extract, (32 being button 6) the second string has the same data but moved one byte over.
0 32 0 0 0 0 0 0 0 0
0 0 32 0 0 0 0 0 0 0
If held for several seconds, and then released i get the third and forth strings. The forth obviously means the release command.
0 32 0 0 0 0 0 0 0 0
0 0 0 32 0 0 0 0 0 0
0 0 0 32 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
Thanks for your help
Andrew