|
Thomas Maierhofer (Tom) wrote: Assuming I am the guy who developed this class, how would I test this class? Thouroughly, I hope.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello guys. How do I send my slave application (in windows forms) multiple commands ? I am trying to show frame rate and video bitrate using two commands in mplayer (running as a slave app in windows form). Bit it shows only one things at a time, alternately. Here is what I am trying
objPlayerProcess.StandardInput.WriteLine("osd_show_property_text ${fps}" + "(FrameRate)");
objPlayerProcess.StandardInput.WriteLine(objPlayerProcess.StandardInput.NewLine);
objPlayerProcess.StandardInput.WriteLine("osd_show_property_text ${video_bitrate}" + "(BitRate)");
How do I show both of them, at the same time ? Thanks for any input.
|
|
|
|
|
There's nothing wrong with the code you're showing here other than I can't see how ${fps} and ${video_bitrate} should be replaced by some value. The actual problem is probably located in your receiving code or display code.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Sascha Lefévre wrote: .... other than I can't see how ${fps} and ${video_bitrate} should be replaced by some value.
Yes. Those will be handled by the player internally. Again, values are being shown but...one by one. Not at the same time.
|
|
|
|
|
With the second sentence of my previous reply I tried to hint at you that you need to provide more information / code
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
The slave application will be receiving them one by one. If you want to send them together, then make a single line of it, or change the slave to accept multiple arguments and wait with processing until there's a "I'm done sending stuff" command.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I tried to send them in single line like this ...
objPlayerProcess.StandardInput.WriteLine("osd_show_property_text ${fps}" + "(FrameRate)" + objPlayerProcess.StandardInput.NewLine + "osd_show_property_text ${video_bitrate}" + "(BitRate)");
I don't know if there exists another method. This did not work either. It shows them alternately.
|
|
|
|
|
..because it is not a single line; there's a newline in there.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
nope. it did not work either. i am kinda stuck.
|
|
|
|
|
Post the code where your player is reading these values and we'll have a look
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
Iam Know how send and received but problem how know the state connected with IP , Port
this my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
namespace etherent_send_and_recive_data
{
public partial class Form1 : Form
{
UdpClient udpClient;
private IPEndPoint ipend;
public Form1()
{
InitializeComponent();
udpClient = new UdpClient();
}
private void send_data_through_etherent( string send_data_ETH)
{
byte[] senddataETH = ASCIIEncoding.ASCII.GetBytes(send_data_ETH);
udpClient.Send(senddataETH,4);
}
private void button1_Click(object sender, EventArgs e)
{
int port;
byte res;
button1.Text = "disconnected";
port = int.Parse(textBox2.Text);
ipend = new IPEndPoint(IPAddress.Parse(textBox1.Text), port);
try
{
udpClient.Connect(ipend);
}
finally
{
button1.Text = "connected";
}
}
private void switch1_StateChanged(object sender, NationalInstruments.UI.ActionEventArgs e)
{
if(switch1.Value==true)send_data_through_etherent("S11E");
else send_data_through_etherent("S10E");
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if(textBox2.Text != string.Empty)
{
if (textBox1.TextLength >= 11) button1.Enabled = true;
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text != string.Empty)
{
if (textBox1.TextLength >= 11) button1.Enabled = true;
}
}
}
}
the problem now in code button1_Click I need know the real state for connected for example if connected the button.text="connected" if closed or not connected button.text="disconnected"
how code for udp client about connected and closed
Regards
|
|
|
|
|
Ummm...UDP is connectionLESS so your question makes no sense.
|
|
|
|
|
Hi,
thank you for my support
Sir my equation how know the state for connection
i mean if press button will connected with ip for example 192.168.1.1 and port for example 10001 her equation how can know the connected with this ip and port is Successfully
now my project when press button is write connected but not iam sure the system is connected with this ip and port
I try to search about how know the state for connection with ip
some time is connected is ok but if closed socket must be program say for me now is disconnected
I hope now clear my equation
Best Regards
|
|
|
|
|
Your using UDP. Again, it's a CONNECTIONLESS protocol. THERE IS NO CONNECTION!
It's like tuning in a radio. The radio station doesn't have a connection to your radio and doesn't guarantee that you can receive the signal.
|
|
|
|
|
Thank Sir Now clear information about UDP
I try using TCP in the same project
Regards
|
|
|
|
|
TCP is like a phone call, UDP is like putting messages in a bottle and tossing them into the sea. If you need persistent connections and reliable communications you need to use TCP. If you do use UDP you have to appreciate that you just get data as it comes in, there is no connection or reliability in the data you receive. UDP is only suitable for a limited number of applications, or maybe if you're on a local LAN with an old-school token-ring network.
|
|
|
|
|
thank sir for this information and thank you for my support
now Iam understand about UDP
please Sir can be modification for my code by use TCP
or can be put small example about connected IP and Recived data and send data by used TCP
Best regards
|
|
|
|
|
Hi,
This code from my friend about how can check the connection
if connected or not also continuous check
public bool TestConnection(string ip)
{
Ping p = new Ping();
try
{
PingReply reply = p.Send(ip, 3000);
if (reply.Status == IPStatus.Success)
return true;
}
catch (Exception e)
{
return false;
}
return false;
for example
private void button2_Click(object sender, EventArgs e)
{
busy = true;
if (TestConnection(textBox2.Text))
{
Byte[] sendBytes = Encoding.ASCII.GetBytes("B");
udpClient.Send(sendBytes, sendBytes.Length);
var receivedData = udpClient.Receive(ref ep);
textBox1.Text = Encoding.ASCII.GetString(receivedData);
label1.Text = Encoding.ASCII.GetString(receivedData);
}
busy = false;
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
if (!busy)
{
Byte[] sendBytes = Encoding.ASCII.GetBytes("C");
udpClient.Send(sendBytes, sendBytes.Length);
var receivedData = udpClient.Receive(ref ep);
textBox1.Text = Encoding.ASCII.GetString(receivedData);
}
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Thread.Sleep(500);
if (TestConnection(textBox2.Text))
{
backgroundWorker1.RunWorkerAsync();
}
else
{
MessageBox.Show("No Device Connected");
}
}
|
|
|
|
|
Hello all, I have a quick question. I have a service running that continually checks the database for a record, if a record exist then it process the record and deletes it. The service starts a thread that runs a while look until it tells it to stop. Is it better to create the connection inside or outside of the loop? Keep in mind that this loop could run for days. See below for the two options:
while (!stopEvent.WaitOne(0, false))
{
using (SqlConnection dbConnection = new SqlConnection(connectionString))
{
dbConnection.Open();
using (SqlCommand dbCommand = new SqlCommand("SELECT * FROM [TableName]", dbConnection))
{
using (SqlDataReader dbReader = dbCommand.ExecuteReader())
{
if (dbReader.Read())
{
}
}
}
}
System.Threading.Thread.Sleep(100);
}
using (SqlConnection dbConnection = new SqlConnection(connectionString))
{
dbConnection.Open();
while (!stopEvent.WaitOne(0, false))
{
using (SqlCommand dbCommand = new SqlCommand("SELECT * FROM [TableName]", dbConnection))
{
using (SqlDataReader dbReader = dbCommand.ExecuteReader())
{
if (dbReader.Read())
{
}
}
}
}
System.Threading.Thread.Sleep(100);
}
|
|
|
|
|
I'd go for option 1 - create and dispose of the connection within the loop. You don't want to hold a connection open when you're not using it, and the Thread.Sleep call isn't using it.
I'd also suggest adding a TOP 1 to your query, since you're only expecting to read and process a single record. Either that, or change the if (dbReader.Read()) { ... } to while (dbReader.Read()) { ... } to read and process all of the returned rows.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Two reasons why you should be creating the connection when you need it and not before the loop.
1) If the connection is broken by something, like a drop in network connectivity, you can recover by creating a new connection inside the loop every time you need it without having to break out of the loop to create a new one.
2) A SQL Server connection seat license ain't cheap. If you had one license to share between multiple applications and users, you'd want your connection to hang on to it for as little time as possible.
Connect as late as you can, run your query, and disconnect as early as you can.
|
|
|
|
|
As already mentioned, creating the connection when you need it is best. ado.net implements connection pooling for you under the covers so although you are opening and closing the connection, in normal operation you're not actually doing anything...when you close in your code ado.net keeps the connection open and adds it to the pool, when you open it is just retrieved from the pool so you're not consuming any resources or creating overhead by repeatedly opening and closing. However it means that when your server is very busy then it allows other processes to use the connection if needed and you might get a different connection, or again as mentioned if the connection breaks for some reason you'll just get a new one.
So, basically, don't worry about rapidly opening and closing connections in terms of resources or overhead, ado.net's connection pooling is helping you out.
|
|
|
|
|
Hello. I'm trying to add image slices (about 6 pixels across) to a pre-created bitmap. The idea is to stitch a large bitmap as images come in from a camera. For the purposes of this example, i've changed to code from a newframe event to a for loop. See below. It works well, except i'm occasionally getting a parameter not valid error when creating the blank bitmap, especially if I have created it one or twice before. I've looked around a bit on the google and the best I can figure is that i'm running out of contiguous memory, which is required to create bitmaps. If that's the problem, then I don't have a solutions. Any help would be greatly appreciated!!!!
<pre>private List<Bitmap> BMPList = new List<Bitmap>();
private Bitmap stitchImage = null;
private Graphics stitchGraphics = null;
private void InitializeStitch()
{
stitchImage = new Bitmap(100000, BMPList[0].Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
stitchGraphics = Graphics.FromImage(stitchImage);
}
private void UninitializeStitch()
{
if (stitchGraphics != null)
stitchGraphics.Dispose();
if (stitchImage != null)
stitchImage.Dispose();
}
private void CreateStitch()
{
if (BMPList.Count > 0)
{
InitializeStitch();
for (int i = 0; i < BMPList.Count; i++)
stitchGraphics.DrawImage(BMPList[i], i * BMPList[i].Width, 0);
using (Bitmap tempBMP = (Bitmap)StitchImage.stitchBMP.Clone(new Rectangle(0, 0, BMPList[0].Width, BMPList[0].Width.Height), StitchImage.stitchBMP.PixelFormat))
{
tempBMP.Save(@"C:\MyTestImage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
Uninitialize();
}
}
|
|
|
|
|
How many items are in this BMPList array? How big are the images in it? How big does this "large image"?
Bitmap objects cannot be infinitely large. Any managed object can only be a maximum of 2GB in size. I get the feeling that you're either filling up memory holding all of these images at once and/or you're making a Bitmap object that's just too large.
|
|
|
|
|
Hello Dave,
Thanks for the reply.
In the example I listed, the bitmap is 100000x640. This will create fine, once, but it's only after I dispose it and then recreate (sometimes it even works several times) that I get the problem. So, I feel like the issue is with continuous memory.
I have seen applications work with much larger bitmaps then this, I just don't know how they do it.
|
|
|
|