I get an exception while trying to set the PortId of a SerialDriver multiple times.
My function searches for a modem and so far it works. But when I use it 5/6 times in a row, I get this error :
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Com.Coronis.Sdk.Serialdriver.Rs232driver.Wrapper.RS232Wrapper.SetPortId(Int32 driver, String Id)
at Com.Coronis.Sdk.Serialdriver.Rs232driver.RS232Driver.SetSerialPortId(String serialPortId)
at environnementTest.Program.Main(String[] args) in Test\Program.cs:line 45
It seems to work fine in C++ so I'm assuming it comes from the wrapper.
Here is the simplified function :
for(inti=1;i<20;i++){try{StringportId="COM"+i.ToString();serialDriver.SetSerialPortId(portId);protocol.SetSerialDriverInstance(serialDriver);protocol.Init();protocol.Open();LocalNodeServiceCommandlocalService=newLocalNodeServiceCommand(NodeServiceId.STACK_SERVICE,newPayload("5005"));LocalNodeServiceResponseresponse=protocol.RequestLocalNodeService(localService);if(response.Status==ResponseStatus.OK_PROTOCOL_SUCCESS){Console.Out.WriteLine(portId+" modem trouvé : "+response.Command.ToString());}else{Console.Out.WriteLine(portId+" modem PAS trouvé ");}protocol.Close();}catch(Exceptionex){if(exisProtocolException){}else{protocol.Close();serialDriver.Close();serialDriver=newRS232Driver();protocol=newWaveport();}}}
Thanks for reading !
Yolan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hye,
Because in our C implementation, we use a loading system for instance, we have to reserved memory for each future possible instance. To limit default memory reservation, we have limited the number of instance to 5.
So if you try to create more than 5 instances, you will have this type of error.
I see in your extracted code that in case of Exception (expect for ProtocolException) you recreate an new instance. It could be the cause of your pb (because of the wrapping, if we don't explicitely destroy the instance, the C associated instance will not be free).
Could you please add following console output in exception part and return to us the console output:
When you say "I think I have to create a new Waveport...", you means now you have removed these new creations & the problem is resolved, or if you not let these creations, you have another problem?
What is connected on your COM1?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
No, I think I need, I must create a new instance. After the "other exception", I can't use anymore my objects Protocol and SerialDriver. Maybe there is another way ?
No devices are connected to my computer, besides the waveport (and my keyboard/mouse).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi guys,
I get an exception while trying to set the PortId of a SerialDriver multiple times.
My function searches for a modem and so far it works. But when I use it 5/6 times in a row, I get this error :
It seems to work fine in C++ so I'm assuming it comes from the wrapper.
Here is the simplified function :
Thanks for reading !
Yolan
Hye,
Because in our C implementation, we use a loading system for instance, we have to reserved memory for each future possible instance. To limit default memory reservation, we have limited the number of instance to 5.
So if you try to create more than 5 instances, you will have this type of error.
I see in your extracted code that in case of Exception (expect for ProtocolException) you recreate an new instance. It could be the cause of your pb (because of the wrapping, if we don't explicitely destroy the instance, the C associated instance will not be free).
Could you please add following console output in exception part and return to us the console output:
Thierry
Last edit: Thierry CHOMAUD 2013-03-21
I could use one instance only but when there is an "other exception", I think I have to create a new Waveport and a new RS232Driver.
Here is the end of the result :
Last edit: Yolan 2013-03-22
When you say "I think I have to create a new Waveport...", you means now you have removed these new creations & the problem is resolved, or if you not let these creations, you have another problem?
What is connected on your COM1?
No, I think I need, I must create a new instance. After the "other exception", I can't use anymore my objects Protocol and SerialDriver. Maybe there is another way ?
No devices are connected to my computer, besides the waveport (and my keyboard/mouse).
For getting available port Ids, we suggest to you to use the new added method GetSerialPortIds in C# Domain (see closed ticket #18 in version 2.1.0)