Relay Board Control uk1104
Relay Board Control uk1104
Relay Board Control uk1104
Relay Board Control uk1104
Relay Board Control uk1104
Relay Board Control uk1104 Relay Board Control uk1104 Relay Board Control uk1104 Relay Board Control uk1104 Relay Board Control uk1104 Relay Board Control uk1104 Relay Board Control uk1104 Relay Board Control uk1104
Relay Board Control uk1104 Relay Board Control uk1104
Relay Board Control uk1104
Go Back  Xtreme Visual Basic Talk > > > Relay Board Control uk1104


Reply
 
Thread Tools Display Modes
  #1  
Old 12-30-2011, 08:55 AM
PKindermann PKindermann is offline
Newcomer
 
Join Date: Dec 2011
Location: Saskatchewan, Canada
Posts: 2
Default Relay Board Control uk1104


Hi, I am very new to serial port communication using vb. I recently purchased a relay controler that uses USB virtual serial port to controll 4 relays. There are commands to turn the relalys on and off. (rel1.on rel1.off etc). These commands, as the relays themself work as I have tried them with an Emulation program (Putty).

I would like to build an interface using VB or whatever is necessary to controll these relays from buttons within a form in Access or Excel. Can someone point me into the right direction? How do I open the serial port? How do I send "rels.on" to turn on all relays, and how do I make the controler read this command.

I have found some examples that are similar to my problem. But the solutions did not work. I have also tried using matlab to open the serial port and send a command, which was received however not executed. could it be that I am sending the commands from my form and the relay board is just not executing the sent commands?

Below is a link to the manual of the device.

http://www.canakit.com/Media/Manuals/UK1104.pdf


The following is the code I have found as an example to turn on all relays (rels.on)
Code:
Option Explicit

'-------------------------------------------------------------------------------

'
' This VB module is a collection of routines to perform serial port I/O without
' using the Microsoft Comm Control component.  This module uses the Windows API
' to perform the overlapped I/O operations necessary for serial communications.
'
' The routine can handle up to 4 serial ports which are identified with a
' Port ID.
'
' All routines (with the exception of CommRead and CommWrite) return an error
' code or 0 if no error occurs.  The routine CommGetError can be used to get
' the complete error message.
'--------------------------------------------------------------------------

Private Sub CommandButton1_Click()

    Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
    Dim lngStatus As Long

    
     intPortID = 5

    ' Open COM port
    lngStatus = CommOpen(intPortID, "COM" & CStr(intPortID), _
        "baud=9600 parity=N data=8 stop=1")
        
End Sub

Private Sub CommandButton2_Click()

    Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
    Dim lngStatus As Long
    Dim strData   As String


    intPortID = 5
    strData = "rels.on"     ' cariage return? line feed? i d know
    

   'Writa data
    lngStatus = CommWrite(intPortID, strData)



End Sub

Private Sub CommandButton3_Click()

    Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
    Dim lngStatus As Long
    Dim strData   As String



    intPortID = 5
    lngStatus = CommRead(intPortID, strData, 10)

End Sub

Private Sub CommandButton4_Click()

   Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
       
       
    intPortID = 1
    Call CommClose(intPortID)
    
End Sub

Last edited by Cerian Knight; 12-30-2011 at 08:39 PM. Reason: Added [code]...[/code] tags.
Reply With Quote
  #2  
Old 12-30-2011, 07:48 PM
PKindermann PKindermann is offline
Newcomer
 
Join Date: Dec 2011
Location: Saskatchewan, Canada
Posts: 2
Default

I have found a very simple solution which works.
Code:
Private Sub CommandButton1_Click()
    'All Relays ON button
    On Error Resume Next    'Error handler
    
    If NETComm5.PortOpen = False Then  'check if the serial port is open
        NETComm5.PortOpen = True       'check if the serial port is open
    End If
    If Err Then MsgBox Error$, 48     'Display error in message box
    
    'Set all outputs to High (serial relay board commands)
    NETComm5.Output = "Rel3.on" + Chr$(13)

End Sub

Private Sub CommandButton2_Click()
    'All Relays OFF button
    On Error Resume Next    'Error handler
    
    If NETComm5.PortOpen = False Then  'if the serial port is closed
        NETComm5.PortOpen = True       'open the serial port
    End If
    If Err Then MsgBox Error$, 48     'Display error in message box
    
    'Set all relays outputs to low (serial relay board commands)
    NETComm5.Output = "Rels.off" + Chr$(13)

End Sub

Private Sub UserForm_Terminate()
    'Close serial port on exit
    On Error Resume Next    'Error handler
    
    If NETComm5.PortOpen = True Then    'check if the serial port is open
        NETComm5.PortOpen = False       'close the serial port
    End If
    If Err Then MsgBox Error$, 48     'Display error in message box
    
End Sub

Last edited by Cerian Knight; 12-30-2011 at 08:38 PM. Reason: Added [code]...[/code] tags.
Reply With Quote
  #3  
Old 12-30-2011, 08:56 PM
Cerian Knight's Avatar
Cerian KnightRelay Board Control uk1104 Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,191
Default

That code is for Office VBA (and using a somewhat deprecated syntax). If you are using VB6, then some additional changes might need to be made (e.g. Form_Unload instead of UserForm_Terminate to close port).
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Relay Board Control uk1104
Relay Board Control uk1104
Relay Board Control uk1104 Relay Board Control uk1104
Relay Board Control uk1104
Relay Board Control uk1104
Relay Board Control uk1104 Relay Board Control uk1104 Relay Board Control uk1104 Relay Board Control uk1104 Relay Board Control uk1104 Relay Board Control uk1104 Relay Board Control uk1104
Relay Board Control uk1104
Relay Board Control uk1104
 
Relay Board Control uk1104
Relay Board Control uk1104
 
-->