|
I had below listed error when I run my program
It works if I selected a different Port.
and it used to work before. I list my program below and the error message. Can anyone tell what is the problem?
Thanks
cbbCOMPorts.SelectedItem = "COM2"
With serialPort
.PortName = cbbCOMPorts.Text
.BaudRate = 9600
.Parity = IO.Ports.Parity.Even
.DataBits = 7
.StopBits = IO.Ports.StopBits.One
.Encoding = System.Text.Encoding.ASCII
.Handshake = IO.Ports.Handshake.XOnXOff
End With
serialPort.Open()
Error Message
"System.IO.IOException: The Operation completed succesfully.
at System.IO.Ports.InternalResources.WinIOError(Int32 ErrorCode, String Str)
at System.IO.Ports.SerialStream..ctor(Sring portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at Lecom_Test_Simulated_Drive.MainPage.bnConnect_Click(Object sender, EventArgs e) in D:\Projects\Lecom Test Simulated Drive\Lecom Test Simulated Drive\Main Page.vb:line 78"
|
|
|
|
|
albchinsh wrote: System.IO.IOException: The Operation completed succesfully
Surely this is not the correct exception message
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
This is exactly the message
"System.IO.IOException: The Operation completed succesfully.
at System.IO.Ports.InternalResources.WinIOError(Int32 ErrorCode, String Str)
at System.IO.Ports.SerialStream..ctor(Sring portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
at System.IO.Ports.SerialPort.Open()
at Lecom_Test_Simulated_Drive.MainPage.bnConnect_Click(Object sender, EventArgs e) in D:\Projects\Lecom Test Simulated Drive\Lecom Test Simulated Drive\Main Page.vb:line 78"
Line 78 is SerialPort.Open()
I had Try..Catch statement enclosing this line
with MsgBox(ex.ToString)
|
|
|
|
|
Still have the problem?
This is what i have used previously to communicate with Serial Ports;
Declarations;
Private WithEvents port As IO.Ports.SerialPort
Port Selection via ComboBox;
Private Sub LoadSerialPortNameList()
ComboBoxSerialPorts.Items.Clear()
For Each item As String In My.Computer.Ports.SerialPortNames
ComboBoxSerialPorts.Items.Add(item)
Next
End Sub
Port Connection via button;
'Check a port is selected
If ComboBoxSerialPorts.SelectedIndex < 0 Then
MsgBox("Select a serial port from the drop down list")
Else
Try
port = My.Computer.Ports.OpenSerialPort(ComboBoxSerialPorts.Items.Item(ComboBoxSerialPorts.SelectedIndex))
Catch ex As Exception
MsgBox("Error Opening Port: " + ex.Message)
End Try
End If
Port Disconnection via button;
If port.IsOpen Then
port.Close()
Debug.WriteLine("Port Closed")
Else
MsgBox("Port is already closed.")
End If
Notice the use of the My.Computer.Ports methods, don't know if that helps you any, but worked for me in the past no problem.
One of the biggest hassles was during dev/testing, if your app bombs, the OS seems to retain the lock on the port resource, leading to connection failures on subsequent runs, needing a reboot to release them.
|
|
|
|
|
Still not possible.
If I changed the same physical port to COM11 (Via control panel)
then it will work.
I wonder what happened to COM2?
|
|
|
|
|
did you try a reboot? AFAIK there are some issues with serial ports loosing their health till reboot.
|
|
|
|
|
Tried Reboot but still not working for COM2
IT will work if I set the same physical port to COM11
DO Not Know why??????????
|
|
|
|
|
I have a winform with a datagridview bound to a dataview. I read in various delimited files with the first row as column headers. I build a datatable in memory & then instantiate the dataview and then bind it to the datagridview. I have a modal form that allows the user to select a column from a combobox & enter a list of values in a multiline textbox. I use the user input to set the dataview.rowfilter property but the datagridview only reflects rows with the first value from the list.
Try
If searchRecords.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
Dim filterString As New StringBuilder
If searchRecords.SearchValues.Count > 1 Then
filterString.Append(searchRecords.SelectedColumn)
filterString.Append(String.Format(" IN ('{0}'", searchRecords.SearchValues(0).ToString))
For i As Integer = 1 To searchRecords.SearchValues.Count - 1
filterString.Append(String.Format(",'{0}'", searchRecords.SearchValues(i).ToString))
Next
filterString.Append(")")
Else
filterString.Append(searchRecords.SelectedColumn)
filterString.Append(" = ")
filterString.Append(String.Format("'{0}'", searchRecords.SearchValues(0).ToString))
End If
_RecordTable.GetView.RowFilter = filterString.ToString
_RecordTable.GetView.RowStateFilter = DataViewRowState.CurrentRows
End If
Catch ex As Exception
Throw ex
End Try
So if the user provides more than one value the filter string would look something like this "columnName IN ('value1','value2','value3')". The result in the datagridview displays only rows with value1 in the columnName column. I have used the exact same code to filter a dataview instantiated with a SQL table & it works. I can't figure out why this code does not work & no one I've asked can explain. Please help!
|
|
|
|
|
I am working on ur issue but i am not able to figure out
the _RecordTable object.
Can u mention what is the type of _RecordTable.
Tej Aj,
http://opexsolution.com/forum/
|
|
|
|
|
_RecordTable is of Type RecordTable which is a class that I built.
Imports System.IO
Imports System.Text
Imports Microsoft.VisualBasic.FileIO
Public Class RecordTable
Private WithEvents _DT As New DataTable
Private _DTList As New List(Of DataTable)
Private _ColumnNames As List(Of String)
Private _FileName As String
Private _TableChanged As Boolean
Private WithEvents _DV As New DataView(_DT)
Friend ReadOnly Property GetView As DataView
Get
Return _DV
End Get
End Property
Friend ReadOnly Property GetTable As DataTable
Get
Return _DT
End Get
End Property
Friend ReadOnly Property DTList As List(Of DataTable)
Get
Return _DTList
End Get
End Property
Friend Property ColumnNames As List(Of String)
Get
Return _ColumnNames
End Get
Set(ByVal value As List(Of String))
_ColumnNames = value
End Set
End Property
Friend Property FileName As String
Get
Return _FileName
End Get
Set(ByVal value As String)
_FileName = value
End Set
End Property
Friend Property TableChanged As Boolean
Get
Return _TableChanged
End Get
Set(ByVal value As Boolean)
_TableChanged = value
End Set
End Property
Public Sub New()
AddHandler _DT.RowChanged, New DataRowChangeEventHandler(AddressOf TableHasChanged)
End Sub
#Region "Form Routines"
Friend Sub ReadRecords()
Dim recordX As Integer = 0
Dim dr As DataRow
Try
_DT.Clear()
Using parser As New TextFieldParser(FileName)
parser.SetDelimiters("|")
While Not parser.EndOfData
' Read in the fields for the current record
Dim fields As String() = parser.ReadFields()
Dim columns As String()
' Add record to data table
If recordX = 0 Then
Dim columnNames As New List(Of String)
columns = fields
For Each column As String In columns
columnNames.Add(column)
_DT.Columns.Add(column)
Next
Me.ColumnNames = columnNames
recordX += 1
Else
Dim i As Integer = 0
dr = _DT.NewRow
For Each field As String In fields
dr.Item(Me.ColumnNames(i)) = field
i += 1
Next
_DT.Rows.Add(dr)
recordX += 1
End If
End While
End Using
_TableChanged = False
Catch ex As Exception
Throw ex
End Try
End Sub
Friend Sub SaveFileAs()
Dim recordBuilder As New StringBuilder
Try
Using outputWriter As New StreamWriter(FileName, False, Encoding.UTF8)
For Each column As DataColumn In _DT.Columns
If _DT.Columns.IndexOf(column.ColumnName) = 0 Then
recordBuilder.Append(column.ColumnName)
Else
recordBuilder.Append(String.Format("|{0}", column.ColumnName))
End If
Next
outputWriter.WriteLine(recordBuilder.ToString)
recordBuilder.Clear()
For Each row As DataRow In _DT.Rows
For Each column As DataColumn In _DT.Columns
If _DT.Columns.IndexOf(column.ColumnName) = 0 Then
recordBuilder.Append(row.Item(column.ColumnName).ToString)
Else
recordBuilder.Append(String.Format("|{0}", row.Item(column.ColumnName).ToString))
End If
Next
outputWriter.WriteLine(recordBuilder.ToString)
recordBuilder.Clear()
Next
End Using
TableChanged = False
Catch ex As Exception
Throw ex
End Try
End Sub
Friend Sub SaveFile()
Dim recordBuilder As New StringBuilder
Try
Using output As New FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write), _
outputWriter As New StreamWriter(output, Encoding.UTF8)
For Each column As DataColumn In _DT.Columns
If _DT.Columns.IndexOf(column.ColumnName) = 0 Then
recordBuilder.Append(column.ColumnName)
Else
recordBuilder.Append(String.Format("|{0}", column.ColumnName))
End If
Next
outputWriter.WriteLine(recordBuilder.ToString)
recordBuilder.Clear()
For Each row As DataRow In _DT.Rows
For Each column As DataColumn In _DT.Columns
If _DT.Columns.IndexOf(column.ColumnName) = 0 Then
recordBuilder.Append(row.Item(column.ColumnName).ToString)
Else
recordBuilder.Append(String.Format("|{0}", row.Item(column.ColumnName).ToString))
End If
Next
outputWriter.WriteLine(recordBuilder.ToString)
recordBuilder.Clear()
Next
End Using
TableChanged = False
Catch ex As Exception
Throw ex
End Try
End Sub
Friend Function GetUniqueFileName()
Dim i As Integer = 2
Dim uniqueFileName As String = FileName
While My.Computer.FileSystem.FileExists(uniqueFileName)
uniqueFileName = String.Format("{0}{1}", uniqueFileName, i)
i += 1
End While
Return uniqueFileName
End Function
Private Sub TableHasChanged(ByVal sender As Object, ByVal e As DataRowChangeEventArgs)
TableChanged = True
End Sub
Friend Function CheckTableUpdates()
Try
If TableChanged Then
Dim result As DialogResult = MessageBox.Show("Would you like to save your changes?", "Save Changes", MessageBoxButtons.YesNoCancel, _
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
Return result
Else
Return Nothing
End If
Catch ex As Exception
Throw ex
End Try
End Function
#End Region
End Class
The link in your other post was not really helpful. I am able to get the results I'm looking for when connecting to a SQL table but my problem is that it doesn't work correctly for this application where my datatable is built dynamically in memory from a delimited flat text file. Thank you so much for trying to help me figure this one out. I hope showing you the RecordTable object will shed some light. If you have any other questions please let me know.
|
|
|
|
|
Check if the below Link's example can be helpful to u
http://opexsolution.com/forum/viewtopic.php?f=17&t=19&p=50#p50
|
|
|
|
|
Does anyone have samples of coding a progress bar for a splash screen.
|
|
|
|
|
What you want to done with Progress bar.
Use timer in splash and increse the value of progress bar in timer.tick for how many times you want to run splash.
then close the form.
If you can think then I Can.
|
|
|
|
|
Like eg_Anubhava suggested, I have a program with a form setup as a splash type of screen and it has a progressbar on the form and a timer with the interval set to 500. Here is the code I used.
Dim intProgressValue As Integer
Private Sub frmReportSplash_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
intProgressValue = 0
End Sub
Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
.
.
.
intProgressValue += 2
If intProgressValue > 100 Then
intProgressValue = 5
End If
Me.ProgressBar.Value = intProgressValue
End Sub
Hope this helps...
Lost in the vast sea of .NET
|
|
|
|
|
Why not just set the progressBar to Style property to Marquee ? That would save all that coding for the same effect.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Didn't know that style existed. I tested it out and yes it basically does the same thing. I'll use that style next time I want a progressbar for just the visual effect. Like TechBearSeattle said, I'm not sure if Daniel Engelkes wanted a visual type of effect or was looking for a progress bar to actually show progress of a certain process.
Thanks!
Lost in the vast sea of .NET
|
|
|
|
|
What, precisely, is the bar measuring the progress of? That is going to have an impact as to how you code your solution. If it is just a timer -- the splash screen will be visible for 10 second and then go away -- you can use a timer.
If you are actually displaying the progress of your application's start-up, though, you will need to do some planning. Set your bar to have a minimum of 0 and a maximum of 100. Then look at everything that the set-up does: read the registry and set variables, locate network resources, manually load libraries, verify user credentials, and so on. Assign each individual step a percentage of your maximum, and reset the bar's value after each step. You might also want to add a status bar at the bottom of the splash to give text feedback.
Private Sub UpdateProgress(ByVal Text As String, ByVal Increment As Integer)
ToolStripStatusLabel1.Text = Text
ToolStripProgressBar1.Value += Increment
StatusStrip1.Invalidate()
End Sub
Public Sub Main()
ToolStripProgressBar1.Minimum = 0
ToolStripProgressBar1.Maximum = 100
ToolStripProgressBar1.Value = 0
UpdateProgress("Verifying user credentials...", 20)
{code}
UpdateProgress("Locating network resources Alpha...", 10)
{code}
UpdateProgress("Locating network resources Beta...", 10)
{code}
UpdateProgress("Locating network resources Gamma...", 10)
{code}
UpdateProgress("Verifying current version...", 25)
{code}
UpdateProgress("Loading MyLib1.dll...", 5)
{code}
UpdateProgress("Loading MyLib2.dll...", 5)
{code}
UpdateProgress("Loading MyLib3.dll...", 5)
{code}
UpdateProgress("Finalizing...", 10)
{code}
Me.Close()
End Sub
When the splash screen closes, the app's main form will launch.
|
|
|
|
|
In my program I create a file using:
dim strFileName as string = "c:\test.txt"
File.Create(My.Settings.strFileName)
I'm just using the file as a basic reference that the program is running and while this file exists don't try and start another instance of the program. I don't use the file or add to it or anything.
Later I try to delete the file using:
File.Delete(My.Settings.strFileName)
I've also tried Kill(My.Settings.strFileName)
Unfortunately I get this error:
The process cannot access the file 'c:\test.txt' because it is being used by another process.
I understand the error, but how do I get the program to let go after I create it so I can delete it later?
Lost in the vast sea of .NET
|
|
|
|
|
You can accomplish the same goal by going to the Project settings, view the Application Tab, and make sure the checkbox that says Make single instance application is checked. Now only one instance of your application can run at a time. Also, if you want to, you can View the Application Events and add and event called the MyApplication_StartupNextInstance. You can add code here to perform a specific task if a user tries to run the application more than once.
Hope this helps.
|
|
|
|
|
My app is being called by a service and isn't really Form based at all. I currently don't have the application framework enabled. This suggestion was great... I didn't know this feature existed, but I'll try it another day on a different app which is more based around forms. Thanks!!
Lost in the vast sea of .NET
|
|
|
|
|
File.Create does not just create a file, it also opens it and returns a reference to the created FileStream .
Try this:
Dim MyFile As FileStream = File.Create(My.Settings.strFileName)
You can then use MyFile to add text. When you are done, call
MyFile.Close
File.Delete(My.Settings.strFileName)
|
|
|
|
|
Thanks!!! That worked perfectly!
Lost in the vast sea of .NET
|
|
|
|
|
If you're using a file to prevent a second instance from being opened, you have a problem. This won't work in all cases since you can have two instances of your app both checking for the existance of the file and both trying to create the file at the same time.
A better solution is to create a Mutex instead. A file can be created by multiple processes at the same time. A Mutex cannot. If two processes try to create the same mutex as the same time, one of them is forced to wait until the other request completes.
Documention on the Mutex class can be found here[^]. Just be sure to read it and to release the Mutex when your app is done with it.
|
|
|
|
|
Thanks! That does sound like a better solution! I'll look into it.
Lost in the vast sea of .NET
|
|
|
|
|
Hi all.
I wrote a directory watcher to monitor a folder for any changes. It works fine when monitoring a local folder and also a folder on the network as long as it's on a windows server.
As soon as want to monitor a samba share(Linux server) it doesn't work.
I am using the "filesystemwatcher" and from what I've heard it only works on a NTFS file system.
Is there a work around for this?
Thanx in advance.
|
|
|
|