5 Replies - 9546 Views - Last Post: 21 February 2013 - 03:53 PM Rate Topic: -----

#1 sai_saketh92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 10-May 12

trying to send data through serial port in VBA

Posted 29 May 2012 - 12:15 AM

trying to send data through serial port in VBA without any 3 rd party applications any ideas??
i have following code but it is not working

Sub serial()
    Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
    Dim lngStatus As Long
    Dim strData   As String
    Dim strData1   As String
    
     intPortID = 6

    ' Open COM port
    lngStatus = CommOpen(intPortID, "COM" & CStr(intPortID), _
        "baud=9600 parity=N data=8 stop=1")
        
        If (lngStatus) Then
     MsgBox "Can not open port", vbCritical
     Else
   MsgBox "Port opened successfully!", vbInformation
   End If
   End Sub
   
   Sub wserial()
    Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
    Dim lngStatus As Long
    Dim strData   As String
    Dim strData1   As String
    
     intPortID = 6

   strData = "/r"
   'Writa data
    lngStatus = CommWrite(intPortID, strData)
If lngStatus Then
MsgBox "Can not write to port" + CStr(intPortID), vbExclamation
Else
MsgBox "Write " + strData + " to" + CStr(intPortID) + " sucessfully!", vbInformation
End If
    
       
   ' lngStatus = CommRead(intPortID, strData1, 1)
    
'If (lngStatus) Then
'MsgBox "Can not read", vbCritical
'Else
'MsgBox "read data successfully", vbInformation
'End If
'Range("A1").Value = strData1
End Sub
Sub rserial()
    Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
    Dim lngStatus As Long
    Dim strData   As String
    Dim strData1   As String
         intPortID = 6
     
    lngStatus = CommRead(intPortID, strData1, 2)
    
If (lngStatus) Then
MsgBox "Can not read", vbCritical
Else
MsgBox "read data successfully", vbInformation
End If
Range("A1").Value = strData1
End Sub

Sub cserial()
Dim intPortID As Integer
     intPortID = 6
    Call CommClose(intPortID)
End Sub




Is This A Good Question/Topic? 0
  • +

Replies To: trying to send data through serial port in VBA

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 301
  • View blog
  • Posts: 1,782
  • Joined: 26-March 09

Re: trying to send data through serial port in VBA

Posted 29 May 2012 - 12:49 AM

Please don't open duplicate topics....

Have a look at this post for some pointers..
Was This Post Helpful? 0
  • +
  • -

#3 sai_saketh92  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 10-May 12

Re: trying to send data through serial port in VBA

Posted 29 May 2012 - 01:32 AM

read my question properly,i said that this code is not working
Was This Post Helpful? -1
  • +
  • -

#4 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 301
  • View blog
  • Posts: 1,782
  • Joined: 26-March 09

Re: trying to send data through serial port in VBA

Posted 29 May 2012 - 04:10 AM

And how was I supposed to know that the snippet of code you posted was related to the link I gave you?

Maybe you'd like to explain what it's actually doing/not doing and not "it doesn't work" and someone else will pick it up, obviously you don't appreciate me trying to assist you.
Was This Post Helpful? 0
  • +
  • -

#5 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: trying to send data through serial port in VBA

Posted 29 May 2012 - 09:10 AM

sai, please don't be rude to the people that are trying to help you. Especially, please don't assume that people who give you answers that you don't like haven't read your questions properly. After all, your question was "any ideas??" You got some ideas.

Finally, if you go over our site and read the directions properly, you will find any number of places that tell you not to simply say that your code doesn't work. It's not our job to fix your code, it's yours. Tell us what you have tried, and give some detail about the error.
Was This Post Helpful? 0
  • +
  • -

#6 camle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-February 13

Re: trying to send data through serial port in VBA

Posted 21 February 2013 - 03:53 PM

View PostBobRodes, on 29 May 2012 - 09:10 AM, said:

sai, please don't be rude to the people that are trying to help you. Especially, please don't assume that people who give you answers that you don't like haven't read your questions properly. After all, your question was "any ideas??" You got some ideas.

Finally, if you go over our site and read the directions properly, you will find any number of places that tell you not to simply say that your code doesn't work. It's not our job to fix your code, it's yours. Tell us what you have tried, and give some detail about the error.

I am trying to do the same thing. do you guys have good code yet??

Thanks

View Postcamle, on 21 February 2013 - 03:48 PM, said:

View PostBobRodes, on 29 May 2012 - 09:10 AM, said:

sai, please don't be rude to the people that are trying to help you. Especially, please don't assume that people who give you answers that you don't like haven't read your questions properly. After all, your question was "any ideas??" You got some ideas.

Finally, if you go over our site and read the directions properly, you will find any number of places that tell you not to simply say that your code doesn't work. It's not our job to fix your code, it's yours. Tell us what you have tried, and give some detail about the error.

I am trying to do the same thing. do you guys have good code yet??

Thanks

I am trying to send it to a cnc machine.
Also can you see the code from excel being sent to the machine in a separate window.

Many Thanks

View Postcamle, on 21 February 2013 - 03:48 PM, said:

View PostBobRodes, on 29 May 2012 - 09:10 AM, said:

sai, please don't be rude to the people that are trying to help you. Especially, please don't assume that people who give you answers that you don't like haven't read your questions properly. After all, your question was "any ideas??" You got some ideas.

Finally, if you go over our site and read the directions properly, you will find any number of places that tell you not to simply say that your code doesn't work. It's not our job to fix your code, it's yours. Tell us what you have tried, and give some detail about the error.

I am trying to do the same thing. do you guys have good code yet??

Thanks

I am trying to send it to a cnc machine.
Also can you see the code from excel being sent to the machine in a separate window.

Many Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1