|
-
Aug 25th, 2020, 08:32 AM
#1
Thread Starter
New Member
-
Aug 25th, 2020, 09:57 AM
#2
Re: Init Problem? Serial Port Comm Program
Hello,
are you sure your device is on port com 2 ? you can find the list of port com available (as a collection of string) with My.Computer.Ports.SerialPortNames.
mdevice is apparently nothing so what is the code and where is it that assign something to mdevice.
for the second error, there is a "new" missing somewhere . which object is affected by this error ?
The best friend of any programmer is a search engine 
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Aug 25th, 2020, 10:13 AM
#3
Thread Starter
New Member
Re: Init Problem? Serial Port Comm Program
Hi Delaney,
Once plugged into the CanBUS adapter, our programs communicate through COM2, yeah. I know it's a little unorthodox, but it has been that way since before I came onboard. I have attached a snippet of the sub that assigns mDevice. In regards to the second error, the error details point to the line " bal = mDevice.OpenBusAccessLayer()".
Thanks for the response!
M
-
Aug 25th, 2020, 10:27 AM
#4
Thread Starter
New Member
Re: Init Problem? Serial Port Comm Program
Hi Delaney,
Yeah, strangely enough, we use Port COM2 here. mDevice gets assigned under a private sub (photo attached), and the 2nd error is referencing the line "bal = mDevice.OpenBusAccessLayer()"
Thanks for the help!
Attachment 178464
-
Aug 25th, 2020, 10:38 AM
#5
Re: Init Problem? Serial Port Comm Program
your attachment doesn't work and is not the good way to present the code (as it is poorly readable), please copy/paste the code between code tags ( click on # in the editor).
for the second error correct the declaration of bal in InitSocket :
Code:
dim bal as new Ixxat.......
The best friend of any programmer is a search engine 
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Aug 25th, 2020, 10:43 AM
#6
Thread Starter
New Member
Re: Init Problem? Serial Port Comm Program
Ah, I see. That's fairly convenient to have this code paste feature.
The code where the mDevice is assigned:
Code:
Private Sub SelectDevice(ByVal DeviceEnumNumber As Long)
'temporary holder for device tag
Dim mTempDevice As Ixxat.Vci3.IVciDevice = Nothing
Dim deviceHardwareID As Object
Try
'populate the device list, this section should be automated and removed
deviceEnum = deviceList.GetEnumerator()
deviceEnum.Reset()
'continue as long as more devices are detected. for our purpose number of devices will always be one
Do While deviceEnum.MoveNext() = True
mTempDevice = deviceEnum.Current
If mTempDevice.VciObjectId = DeviceEnumNumber Then
mDevice = mTempDevice
' a sample how to read the unique hardware ID from the device
deviceHardwareID = mTempDevice.UniqueHardwareId
End If
Loop
Catch ex As Exception
' todo show the exception
End Try
End Sub
When I add new in the declaration of bal, I get an error that states I can't "use New on an interface"
-
Aug 25th, 2020, 11:06 AM
#7
Re: Init Problem? Serial Port Comm Program
either deviceEnum or deviceList is empty or this mTempDevice.VciObjectId = DeviceEnumNumber is never achieved
let try to debug
put a msgbow("fail") in the catch part (to verify if you have an exception)
after that line :
mTempDevice = deviceEnum.Current
put a msgbox(mTempDevice.VciObjectId.tostring) to check what you get
The best friend of any programmer is a search engine 
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Aug 25th, 2020, 11:17 AM
#8
Thread Starter
New Member
Re: Init Problem? Serial Port Comm Program
The errors remained the same. Attachment 178465 <-- This one is pointing to the bal = mDevice... line, and Attachment 178466 no message showed up for mTempDevice
-
Aug 25th, 2020, 11:21 AM
#9
Re: Init Problem? Serial Port Comm Program
ok for the second error, it may not be a bal problem but a mdevice problem which is not created.
do you have somewhere in you code something like this (or close) :
Code:
dim mdevice as new Ixxat.Vci3.IVciDevice
by the way do you have on VS the option explicit on ON? if not put it...
The best friend of any programmer is a search engine 
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Aug 25th, 2020, 11:26 AM
#10
Re: Init Problem? Serial Port Comm Program
 Originally Posted by LostintheCode
that's means you don't go into the loop or the list is empty.
when do you call the sub select device ? before or after BtnTestStart ?
The best friend of any programmer is a search engine 
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Aug 25th, 2020, 11:42 AM
#11
Thread Starter
New Member
Re: Init Problem? Serial Port Comm Program
 Originally Posted by Delaney
ok for the second error, it may not be a bal problem but a mdevice problem which is not created.
do you have somewhere in you code something like this (or close) :
Code:
dim mdevice as new Ixxat.Vci3.IVciDevice
by the way do you have on VS the option explicit on ON? if not put it...
With the exception of the declaration statements
Code:
Private mDevice As Ixxat.Vci3.IVciDevice = Nothing
Private mCanChn As Ixxat.Vci3.Bal.Can.ICanChannel = Nothing
Private mReader As Ixxat.Vci3.Bal.Can.ICanMessageReader = Nothing
Private mWriter As Ixxat.Vci3.Bal.Can.ICanMessageWriter = Nothing
Private mCanCtl As Ixxat.Vci3.Bal.Can.ICanControl = Nothing
I dont see mDevice being declared/defined anywhere else
-
Aug 25th, 2020, 11:43 AM
#12
Thread Starter
New Member
Re: Init Problem? Serial Port Comm Program
 Originally Posted by Delaney
that's means you don't go into the loop or the list is empty.
when do you call the sub select device ? before or after BtnTestStart ?
Select device is being called before the btnTestStart. Would possibly moving it to the form load event help this?
-
Aug 25th, 2020, 11:50 AM
#13
Re: Init Problem? Serial Port Comm Program
try to replace
Code:
Private mDevice As Ixxat.Vci3.IVciDevice = Nothing
by
Code:
Private mDevice As new Ixxat.Vci3.IVciDevice = Nothing
where do you declare that ?
Unfortunately, as it is late in France, I won't be able to help you more and much tonight (for me ).
The best friend of any programmer is a search engine 
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Aug 25th, 2020, 12:53 PM
#14
Thread Starter
New Member
Re: Init Problem? Serial Port Comm Program
 Originally Posted by Delaney
try to replace
Code:
Private mDevice As Ixxat.Vci3.IVciDevice = Nothing
by
Code:
Private mDevice As new Ixxat.Vci3.IVciDevice = Nothing
where do you declare that ?
Unfortunately, as it is late in France, I won't be able to help you more and much tonight (for me  ).
I understand. Thank you for the help. The declaration of mDevice is in the form load event as shown
Code:
Public Class Form1
'variables to run/initialize can connection
Private mDevice As Ixxat.Vci3.IVciDevice = Nothing
Private mCanChn As Ixxat.Vci3.Bal.Can.ICanChannel = Nothing
Private mReader As Ixxat.Vci3.Bal.Can.ICanMessageReader = Nothing
Private mWriter As Ixxat.Vci3.Bal.Can.ICanMessageWriter = Nothing
Private mCanCtl As Ixxat.Vci3.Bal.Can.ICanControl = Nothing
'device list variables, working to remove
Private deviceManager As Ixxat.Vci3.IVciDeviceManager = Nothing
Private deviceList As Ixxat.Vci3.IVciDeviceList = Nothing
Private deviceEnum As IEnumerator = Nothing
When I change the code to
Code:
]Private mDevice As new Ixxat.Vci3.IVciDevice = Nothing
I get the error stating I cannot use "new" on an interface.
-
Aug 25th, 2020, 04:10 PM
#15
Re: Init Problem? Serial Port Comm Program
I must confess that I am lost.
I manage to find an IXXAT sample vb.net program which is close to yours. and some manual. CAN bus is not something I know so I am afraid I won't be able to help you more than that. I don't have CAN device, so I cannot test it
I would advice you to start with that sample program and try to make it works and understand how it works and what are the difference with yours.
https://cdn.hms-networks.com/docs/li...sn=b3eb48d7_22
the link contains a large zip file with several sample programs in several language + manuals + api etc...
I found the link here : https://www.ixxat.com/technical-supp...olete-products
The best friend of any programmer is a search engine 
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Aug 26th, 2020, 08:28 AM
#16
Thread Starter
New Member
Re: Init Problem? Serial Port Comm Program
 Originally Posted by Delaney
I must confess that I am lost.
I manage to find an IXXAT sample vb.net program which is close to yours. and some manual. CAN bus is not something I know so I am afraid I won't be able to help you more than that. I don't have CAN device, so I cannot test it
I would advice you to start with that sample program and try to make it works and understand how it works and what are the difference with yours.
https://cdn.hms-networks.com/docs/li...sn=b3eb48d7_22
the link contains a large zip file with several sample programs in several language + manuals + api etc...
I found the link here : https://www.ixxat.com/technical-supp...olete-products
Thank you for the help, I will take a look at the sample files
-
Aug 26th, 2020, 12:03 PM
#17
Re: Init Problem? Serial Port Comm Program
 Originally Posted by LostintheCode
I understand. Thank you for the help. The declaration of mDevice is in the form load event as shown
Code:
Public Class Form1
'variables to run/initialize can connection
Private mDevice As Ixxat.Vci3.IVciDevice = Nothing
Private mCanChn As Ixxat.Vci3.Bal.Can.ICanChannel = Nothing
Private mReader As Ixxat.Vci3.Bal.Can.ICanMessageReader = Nothing
Private mWriter As Ixxat.Vci3.Bal.Can.ICanMessageWriter = Nothing
Private mCanCtl As Ixxat.Vci3.Bal.Can.ICanControl = Nothing
'device list variables, working to remove
Private deviceManager As Ixxat.Vci3.IVciDeviceManager = Nothing
Private deviceList As Ixxat.Vci3.IVciDeviceList = Nothing
Private deviceEnum As IEnumerator = Nothing
When I change the code to
Code:
]Private mDevice As new Ixxat.Vci3.IVciDevice = Nothing
I get the error stating I cannot use "new" on an interface.
Correct, you can't create an instancce of an interface... you can create an object that implements that interface, but an interface by itself cannot be instanciated.
ergo, if the mDevice isn't being created on the line it is declared on (also, I don't think you can New an instance and set it to nothing at the same time, because, what's the point? What's the intent? Do you want the object, or nothing? Can't have both.) ... it should be set somewhere else then (looks like inside SelectDevice).... which isn't happening, which may be due to the first error... What it sounds like is happening is that SelectDevice is failing to find the device, and as a result mDevice doesn't get set, and there's other code further downstream that's called that IS using mDevice with out first checking to see if it is not nothing... but since it is... error.
If it were me, I'd put a breakpoint on the first line of code in SelectDevice and then step through it, one line at a time, checking the value of everything, and seeing what it is really doing in there, and then working backwards to why it's not working as expected.
ie: it's not entering the loop because deviceEnum is empty... ok, so why is deviceEnum empty? Well, it's because deviceList is empty.... ok, why is deviceList empty then? Well, it's because ........ and so on...
-tg
-
Aug 27th, 2020, 09:24 AM
#18
Thread Starter
New Member
Re: Init Problem? Serial Port Comm Program
 Originally Posted by techgnome
Correct, you can't create an instancce of an interface... you can create an object that implements that interface, but an interface by itself cannot be instanciated.
ergo, if the mDevice isn't being created on the line it is declared on (also, I don't think you can New an instance and set it to nothing at the same time, because, what's the point? What's the intent? Do you want the object, or nothing? Can't have both.) ... it should be set somewhere else then (looks like inside SelectDevice).... which isn't happening, which may be due to the first error... What it sounds like is happening is that SelectDevice is failing to find the device, and as a result mDevice doesn't get set, and there's other code further downstream that's called that IS using mDevice with out first checking to see if it is not nothing... but since it is... error.
If it were me, I'd put a breakpoint on the first line of code in SelectDevice and then step through it, one line at a time, checking the value of everything, and seeing what it is really doing in there, and then working backwards to why it's not working as expected.
ie: it's not entering the loop because deviceEnum is empty... ok, so why is deviceEnum empty? Well, it's because deviceList is empty.... ok, why is deviceList empty then? Well, it's because ........ and so on...
-tg
Tg,
That's a pretty solid idea. I know that deconstruction is a viable option, it's just so hard sometimes when you're stuck in your head on a problem. So I'm starting at the beginning of the updated button click event here
Code:
Dim CurListViewItem As ListViewItem
CurListViewItem = ListViewAvailInterfaces.SelectedItems(0)
'disable get status timer
TimerGetStatus.Enabled = False
'if controller is already open, close existing before opening new one
CloseCurrentExistingController()
'get tag for currently selected item
If CurListViewItem IsNot Nothing Then
'MessageBox.Show(CurListViewItem.Tag.ToString())
SelectDevice(CurListViewItem.Tag)
InitSocket(0)
'disable initialize button after it has been clicked
ButtonInit.Enabled = False
'enable getstatus timer again
TimerGetStatus.Enabled = True
End If
'open a com port for use in sending serial commands to test card
Try
' Get the selected COM port's name from the combo box.
If Not myComPort.IsOpen Then
myComPort.PortName = "COM2"
' Get the selected bit rate from the combo box.
myComPort.BaudRate = 19200
' Set other port parameters.
myComPort.Parity = Parity.None
myComPort.DataBits = 8
myComPort.StopBits = StopBits.One
myComPort.Handshake = Handshake.None
myComPort.ReadTimeout = 3000
myComPort.WriteTimeout = 5000
myComPort.ReadTimeout = 1000
myComPort.WriteTimeout = 1000
' Open the port.
myComPort.Open()
End If
Catch ex As InvalidOperationException
MessageBox.Show(ex.Message)
Catch ex As UnauthorizedAccessException
MessageBox.Show(ex.Message)
Catch ex As System.IO.IOException
MessageBox.Show(ex.Message)
End Try
canMessage.Identifier = &H10A
canMessage.DataLength = 8
canMessage.Data(0) = "&H24"
canMessage.Data(1) = "&H21"
canMessage.Data(2) = "&H1E"
canMessage.Data(3) = "&H1C"
canMessage.Data(4) = "&H1A"
canMessage.Data(5) = "&H18"
canMessage.Data(6) = "&H16"
canMessage.Data(7) = "&H14"
If mWriter.Capacity > 0 Then
mWriter.SendMessage(canMessage)
End If
System.Threading.Thread.Sleep(500)
MessageBox.Show("OK")
'While comTemp.Length < 1
' Try
' comTemp = myComPort.ReadLine()
' Catch ex As Exception
' End Try
'End While
'comTemp = ""
canMessage.Identifier = &H10A
canMessage.DataLength = 8
canMessage.Data(0) = "&H00"
canMessage.Data(1) = "&H11"
canMessage.Data(2) = "&HF"
canMessage.Data(3) = "&HD"
canMessage.Data(4) = "&H7"
canMessage.Data(5) = "&H5"
canMessage.Data(6) = "&H26"
canMessage.Data(7) = "&H25"
If mWriter.Capacity > 0 Then
mWriter.SendMessage(canMessage)
End If
System.Threading.Thread.Sleep(50)
myComPort.Write("OK")
canMessage.Identifier = &H10A
canMessage.DataLength = 8
canMessage.Data(0) = "&H00"
canMessage.Data(1) = "&H2"
canMessage.Data(2) = "&H23"
canMessage.Data(3) = "&H22"
canMessage.Data(4) = "&H20"
canMessage.Data(5) = "&H1D"
canMessage.Data(6) = "&H1B"
canMessage.Data(7) = "&H19"
If mWriter.Capacity > 0 Then
mWriter.SendMessage(canMessage)
End If
System.Threading.Thread.Sleep(50)
myComPort.Write("OK")
canMessage.Identifier = &H10A
canMessage.DataLength = 8
canMessage.Data(0) = "&H00"
canMessage.Data(1) = "&H15"
canMessage.Data(2) = "&H13"
canMessage.Data(3) = "&H12"
canMessage.Data(4) = "&H10"
canMessage.Data(5) = "&HE"
canMessage.Data(6) = "&HC"
canMessage.Data(7) = "&H8"
If mWriter.Capacity > 0 Then
mWriter.SendMessage(canMessage)
End If
System.Threading.Thread.Sleep(50)
myComPort.Write("OK")
canMessage.Identifier = &H10A
canMessage.DataLength = 8
canMessage.Data(0) = "&H00"
canMessage.Data(1) = "&H4"
canMessage.Data(2) = "&H27"
canMessage.Data(3) = "&H1F"
canMessage.Data(4) = "&H17"
If mWriter.Capacity > 0 Then
mWriter.SendMessage(canMessage)
End If
System.Threading.Thread.Sleep(50)
myComPort.Write("OK")
End Sub
and I'm looking at the lines
Code:
Dim CurListViewItem As ListViewItem
CurListViewItem = ListViewAvailInterfaces.SelectedItems(0)
for
Code:
CurListViewItem = ListViewAvailInterfaces.SelectedItems(0)
The sub is
Code:
Private Sub ListViewAvailInterfaces_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListViewAvailInterfaces.SelectedIndexChanged
ButtonInit.Enabled = True
ShowDeviceHardwareID()
End Sub
which leads me to
Code:
Private Sub ShowDeviceHardwareID()
Dim CurListViewItem As ListViewItem
Dim selIndex As Windows.Forms.ListView.SelectedIndexCollection
selIndex = ListViewAvailInterfaces.SelectedIndices()
If selIndex.Count > 0 Then
CurListViewItem = ListViewAvailInterfaces.SelectedItems(0)
If CurListViewItem IsNot Nothing Then
SelectDevice(CurListViewItem.Tag)
End If
End If
End Sub
My question right off the bat is, looking at the code map that I sent above, isn't the Dim of CurLustViewItem in both places unneccessary, and also, I feel like there is an issue within the nested If statements. Like I posted originally, I am inheriting the code in this situation, and can't really speak on why it was constructed the way it was.
Thanks for any help with this.
M
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|