|
Parag Raibagkar wrote: This works only if i want to upload image
Wrong. An image is nothing but a stream of bytes, just like any other file. If you give the LoadFromFile method just the filename, it's assuming that the file is in whatever the CurrentDriectory is. Instead of trying to change the current directory, give the LoadFromFile method the fully qualified path to the file you're trying to upload into the database.
|
|
|
|
|
I have an application using multithreading to read and parse a stream of data from the serial port into packets and extract information out of it to be displayed by the main thread using DirectX interface.
The application is working properly etc, but the thread that reads and parses the com port information is utilising close to 100% cpu usage which is rather annoying me and im not sure what to do about it...a fragment of the code is posted below:
Packets are streamed from the device at 100ms intervals, and the program can't afford to back buffer as the information it is displaying needs to be live, nor can it miss a packet as it needs to check each packet for a particular condition that doesnt get repeated once it occurs...
Public Sub CommReadThread()
Dim bByte As Byte, bPacket(73) As Byte, lResult As Long, tsData As TimeSpan
Try
LinkDev = New SerialPort("COM1", 19200)
LinkDev.Open()
Catch ex As Exception
MsgBox("COM ERROR: " & ex.Message)
Exit Sub
End Try
While bStop = False
tsData = DateTime.Now.Subtract(_iLastData)
CommIdleTime = tsData.TotalMilliseconds
CommBufferSize = LinkDev.BytesToRead
'If no data received for period, flag as disconnected
If CommIdleTime >= _dataTiemout Then
bIsConnected = False
Else
bIsConnected = True
End If
If CommBufferSize > 0 Then
If iFFCount = 2 Then
'found a header, read the rest of the packet
If CommBufferSize >= 70 Then
lResult = LinkDev.Read(bPacket, 0, 70)
_iLastData = DateTime.Now
'Build the packet putting the header back in there for processing
For x As Integer = UBound(bPacket) To 2 Step -1
bPacket(x) = bPacket(x - 2)
Next
bPacket(0) = &HFF
bPacket(1) = &HFF
bPacket(2) = &HFF
LinkPacket = New Packet(bPacket)
'...do packet processing, the New function of the packet class processes it...
LinkPacket = Nothing
iFFCount = 0
End If
Else
'Find a header in the data stream
bByte = LinkDev.ReadByte()
_iLastData = DateTime.Now
If iFFCount > 0 Then
If Hex(bByte) <> "FF" Then
iFFCount = 0
End If
End If
If Hex(bByte) = "FF" Then
iFFCount += 1
End If
End If
End If
End While
End Sub
modified on Monday, December 7, 2009 6:59 AM
|
|
|
|
|
Have you looked at using the DataReceived event? From what I can see of your code here, it looks as if you are just whizzing round in a while loop constantly checking to see if there is anything to read from the port. So you are burning up CPU time doing nothing. The DataReceived event means that you can sit and wait and do nothing until something is ready to read from the port, then you grab it and process it. That might help.
|
|
|
|
|
yeah i was using that before...its just the header of the packet can be anywhere in the stream and the stream is constant thats all...working on extracting the individual packets was proving interesting...hence why i went with this approach...
find the header, wait until the entire packet is in the buffer and read it in, find the next header, wait for the packet...and so on...
|
|
|
|
|
Well, if you have a constant stream then DataReceived probably won't help because there will always be something to read. If you have a constant stream of data to read and parse, I'm not sure what else you can do except throttle back the rate at which you're reading it.
I suppose you could sleep the thread for a few milliseconds before reading from the port if you don't find a header. I don't know the exact requirements for your application, but would it really be that big a deal if there was a 10 millisecond delay before a message header was processed? Actually, even if you specify Sleep(0) immediately before the read it might help because it will yield the thread and give other threads a chance to cut in and do some processing. It's a bit clunky but it would reduce the amount of CPU time the thread is using.
|
|
|
|
|
sorry I'm not reading your code unless you edit it and put it in PRE tags, resulting in proper coloring and indentation.
[ADDED] you should not have polling loops without delays, so when no data is available, waste some time by calling Thread.Sleep(30); or use events. And watch for incomplete packets! [/ADDED]
modified on Monday, December 7, 2009 7:31 AM
|
|
|
|
|
honestly if that's how you feel, then don't read it, simple, I really don't need to know u don't want to read my code, thanks for letting me know tho...its in CODE tags at the moment but i'll change it to PRE...
to be honest I diddn't realise it diddn't indent as I don't post on here too often...a simple "hey, try using the PRE tags instead of CODE tags and your code should indent properly and will be easier for people to read" wouldn't really be be so hard would it? its probably even less characters to type...
|
|
|
|
|
the fix is simple, and much shorter than your above message. However I'm not sure you are really interested, as you downvoted my previous message. Making code readable is the first step to solving problems, and me asking and you adding PRE tags did help. I think I'll wait for you to change your vote.
|
|
|
|
|
Luc Pattyn wrote: as you downvoted my previous message
I balanced it.
Best wishes,
Navaneeth
|
|
|
|
|
|
I need to know how to be able to type a quotation mark into a text box in Visual Basic 2008.
like so...
TextBox1.Text = "[a href=""]LINK[/a]"
Had to substitute the < and > for [ and ].
That is a bad example, because I've already gotten that to work for me... but like how to get the Quotes after the href= to show up in the textbox.
|
|
|
|
|
You already did it. VB.NET uses two double-quote marks to escape one. So, this:
TextBox1.Text = "<a href="""">LINK</a>"
will show this in the textbox:
<a href="">LINK</a>
|
|
|
|
|
I have two form :
class form1 'parent form
dim number as integer
public sub create ()
dim f2 as new form2
f2.MdiParent = me
f2.show()
end sub
public sub test()
end sub
endclass
In form2.vb how to use variable number and method test
thank you very much
Regards
|
|
|
|
|
If "test" is an event handler, you should be using a delegate to handle the event in other forms. If it a method that provides some common functionality, it should be placed in a separate class file, something like "Common.vb" and should be placed there. There you can have it as an internal static or an internal method to call it in any of the forms in your application.
You can make the method internal in the MDI parent itself and access it in the child using Me.MDIParent property.
To access the variable number, you can make use of a internal/public property and can access it using me.MDIParent again.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
In Form1:
Public number As Integer
In Form2:
Form1.Test()
Debug.Writeline(Form1.number.ToString)
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
|
This is a graduation project and you're asking us for the code to solve a problem?? You don't really deserve to graduate then, do you?
If you can't dig around in your brain and write the code yourself, what good is your degree then?
|
|
|
|
|
Dave Kreskowiak wrote: a graduation project and you're asking us for the code to solve a problem?
Oh gawd, I go away for some time, and these types of posts still float around here?
Dave Kreskowiak wrote: If you can't dig around in your brain and write the code yourself, what good is your degree then?
Excellent point.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Notice the rush to serve up some code to you. Seriously if you looked through the forum your would run across this type of question regularly and they always get a negative response. Do your own work, as Dave said what good is serving up someone elses code as your graduation project. Thats called CHEATING.
You've thought of an idea (half the job) now do the research to find out how you can make it work. Excercise those little grey cells in there and try Google.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
it's not that i'm looking for the solution easily..i tried brainstorming for long bt got tired..!
i only need tips that will make me think easily..if ur not gonna help then why is this website available then..!
|
|
|
|
|
People here, generally, do not spoon feed. Also, you are doing a course that expects you to learn something. If you search the web and find some code and just copy paste it to pass, then there no use doing the course.
Here are a couple of things to think about:
1. How are you going to send the notification? Mail, popup, alarm etc?
2. What kind of application this is? Windows based, web based?
At a very high level, your application should work like this:
Any time something is sold, you will be updating the quantity in database. At the same time place check such that when the product quantity goes below a certain level send your notification.
In the end it is your project so you should be thinking about this. In case you get stuck during the project and have a specific question, post it here and and I am sure some one will show you the right way.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
yea i guess ur right...thx for the tips anyway...
|
|
|
|
|
I wasn't trying to give you a smart ass answer. I wasn't sure but I though you were just asking how to display the message. If you were asking how to do this project though it's like d@nish said, people will point you in the right direction or give you 1 or 2 lines of code but they aren't going to write your whole program for you.
|
|
|
|
|
MikeMarq wrote: I wasn't sure but I though you were just asking how to display the message.
4th year compsci student needs a tutorial on MessageBox.Show()? Ouch. Not much belief in the education system, huh?
|
|
|
|