|
You can check current System DateTime and every 5 minutes run your application.
Another way to do this is with a Windows Service.
Best Regards.
|
|
|
|
|
So what's wrong with my first reply? Use timer classes available in .Net Framework to run code every five minutes and use SerialPort class for sending at commands and reading responses.
|
|
|
|
|
Possibly a Windows Service, but a Windows Scheduled Task would be simpler.
|
|
|
|
|
Hi all!
Continuing my serial port fight ...
This time, i'm trying to make sequential Gsm Calls to diferent Gsm numbers. I'm doing some tests, but something's wrong.
My first dial connection is working fine, but when i close it and try to make the next connection, my application turns blocked... and i can't make other dial... Someone could help me with this? The use of filesystemwatcher is only for test purposes.
The code i'm using is here:
public bool GsmConnected;
public bool GsmConnected2;
public Form1()
{
InitializeComponent();
FileInfo finfo = new FileInfo("C:\\Users\\AJorge\\Desktop\\GsmStatus.txt");
StreamWriter ff = finfo.CreateText();
ff.Close();
InitComPort();
this.Show();
aux_function();
}
private void InitComPort()
{
axMSComm1.CommPort = 4;
if (axMSComm1.PortOpen)
axMSComm1.PortOpen = false;
axMSComm1.RThreshold = 1;
axMSComm1.Settings = "115200,n,8,1";
axMSComm1.DTREnable = true;
axMSComm1.RTSEnable = true;
axMSComm1.CDTimeout = 10000;
axMSComm1.Handshaking = MSCommLib.HandshakeConstants.comNone;
axMSComm1.InputMode = MSCommLib.InputModeConstants.comInputModeBinary;
axMSComm1.InputLen = 0;
axMSComm1.NullDiscard = false;
axMSComm1.OnComm += new System.EventHandler(this.axMSComm1_OnComm);
try
{
axMSComm1.PortOpen = true;
}
catch (Exception e)
{
richTextBox1.AppendText(e.ToString());
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void CheckGsmStatus(object sender, FileSystemEventArgs e)
{
StreamReader fileReader = new StreamReader("C:\\Users\\AJorge\\Desktop\\GsmStatus.txt");
string ReadAll = fileReader.ReadToEnd();
string[] ReadAll_Array = ReadAll.Split(new char[] { ' ' });
for (int i = 0; i < ReadAll_Array.Length; i++)
{
if (ReadAll_Array[i] == "13" && ReadAll_Array[i + 1] == "10" && ReadAll_Array[i + 2] == "67" && ReadAll_Array[i + 3] == "79" && ReadAll_Array[i + 4] == "78" && ReadAll_Array[i + 5] == "78" && ReadAll_Array[i + 6] == "69" && ReadAll_Array[i + 7] == "67" && ReadAll_Array[i + 8] == "84" && ReadAll_Array[i + 9] == "32" && ReadAll_Array[i + 10] == "57" && ReadAll_Array[i + 11] == "54" && ReadAll_Array[i + 12] == "48" && ReadAll_Array[i + 13] == "48" && ReadAll_Array[i + 14] == "13" && ReadAll_Array[i + 15] == "10")
GsmConnected = true;
else if (ReadAll_Array[i] == "13" && ReadAll_Array[i + 1] == "10" && ReadAll_Array[i + 2] == "78" && ReadAll_Array[i + 3] == "79" && ReadAll_Array[i + 4] == "32" && ReadAll_Array[i + 5] == "67" && ReadAll_Array[i + 6] == "65" && ReadAll_Array[i + 7] == "82" && ReadAll_Array[i + 8] == "82" && ReadAll_Array[i + 9] == "73" && ReadAll_Array[i + 10] == "69" && ReadAll_Array[i + 11] == "82" && ReadAll_Array[i + 12] == "13" && ReadAll_Array[i + 13] == "10")
this.Close();
}
fileReader.Close();
}
private void CheckGsmStatus2(object sender, FileSystemEventArgs e)
{
StreamReader fileReader = new StreamReader("C:\\Users\\AJorge\\Desktop\\GsmStatus.txt");
string ReadAll = fileReader.ReadToEnd();
string[] ReadAll_Array = ReadAll.Split(new char[] { ' ' });
for (int i = 0; i < ReadAll_Array.Length; i++)
{
if (ReadAll_Array[i] == "13" && ReadAll_Array[i + 1] == "10" && ReadAll_Array[i + 2] == "67" && ReadAll_Array[i + 3] == "79" && ReadAll_Array[i + 4] == "78" && ReadAll_Array[i + 5] == "78" && ReadAll_Array[i + 6] == "69" && ReadAll_Array[i + 7] == "67" && ReadAll_Array[i + 8] == "84" && ReadAll_Array[i + 9] == "32" && ReadAll_Array[i + 10] == "57" && ReadAll_Array[i + 11] == "54" && ReadAll_Array[i + 12] == "48" && ReadAll_Array[i + 13] == "48" && ReadAll_Array[i + 14] == "13" && ReadAll_Array[i + 15] == "10")
GsmConnected2 = true;
if (ReadAll_Array[i] == "13" && ReadAll_Array[i + 1] == "10" && ReadAll_Array[i + 2] == "78" && ReadAll_Array[i + 3] == "79" && ReadAll_Array[i + 4] == "32" && ReadAll_Array[i + 5] == "67" && ReadAll_Array[i + 6] == "65" && ReadAll_Array[i + 7] == "82" && ReadAll_Array[i + 8] == "82" && ReadAll_Array[i + 9] == "73" && ReadAll_Array[i + 10] == "69" && ReadAll_Array[i + 11] == "82" && ReadAll_Array[i + 12] == "13" && ReadAll_Array[i + 13] == "10")
this.Close();
}
fileReader.Close();
}
private void aux_function()
{
try
{
GsmConnected = false;
if (!axMSComm1.PortOpen)
axMSComm1.PortOpen = true;
axMSComm1.Output = "ATD" + "GsmNumber1" + "\r\n";
}
catch (Exception er7)
{
richTextBox1.AppendText(er7.ToString());
}
richTextBox1.AppendText("Dialing with " + "GsmNumber1" + "...");
fileSystemWatcher1.Path = "C:\\Users\\AJorge\\Desktop\\";
fileSystemWatcher1.Filter = "GsmStatus.txt";
fileSystemWatcher1.NotifyFilter = NotifyFilters.LastWrite;
fileSystemWatcher1.Changed += new FileSystemEventHandler(CheckGsmStatus);
fileSystemWatcher1.EnableRaisingEvents = true;
do
{
Application.DoEvents();
} while (!GsmConnected);
fileSystemWatcher1.EnableRaisingEvents = false;
axMSComm1.Output = "+++\r\n";
axMSComm1.Output = "ATH0\r\n";
Thread.Sleep(2000);
axMSComm1.PortOpen = false;
Thread.Sleep(2000);
InitComPort();
File.Delete("C:\\Users\\AJorge\\Desktop\\GsmStatus.txt");
FileInfo f12 = new FileInfo("C:\\Users\\AJorge\\Desktop\\GsmStatus.txt");
StreamWriter xpto2 = f12.CreateText();
xpto2.Close();
DateTime Begins = DateTime.Now;
DateTime Stops = new DateTime();
do
{
Application.DoEvents();
Stops = DateTime.Now;
} while (Stops.Second - Begins.Second != 10);
try
{
GsmConnected2 = false;
if (!axMSComm1.PortOpen)
axMSComm1.PortOpen = true;
axMSComm1.Output = "ATD" + "GsmNumber2" + "\r\n";
}
catch (Exception er7)
{
richTextBox1.AppendText(er7.ToString());
}
richTextBox1.AppendText("\nDialing with " + "GsmNumber2" + "...");
fileSystemWatcher1.Path = "C:\\Users\\AJorge\\Desktop\\";
fileSystemWatcher1.Filter = "GsmStatus.txt";
fileSystemWatcher1.NotifyFilter = NotifyFilters.LastWrite;
fileSystemWatcher1.Changed += new FileSystemEventHandler(CheckGsmStatus2);
fileSystemWatcher1.EnableRaisingEvents = true;
do
{
Application.DoEvents();
} while (!GsmConnected2);
fileSystemWatcher1.EnableRaisingEvents = false;
axMSComm1.Output = "+++\r\n";
axMSComm1.Output = "ATH0\r\n";
}
private void axMSComm1_OnComm(object sender, EventArgs e)
{
switch (axMSComm1.CommEvent)
{
case ((short)MSCommLib.OnCommConstants.comEvReceive):
byte[] b1 = (byte[])axMSComm1.Input;
FileInfo finfo = new FileInfo("C:\\Users\\AJorge\\Desktop\\GsmStatus.txt");
StreamWriter ff = finfo.AppendText();
for (int x = 0; x < b1.Length; x++)
{
richTextBox1.AppendText(b1[x].ToString());
ff.Write("{0} ", b1[x]);
}
ff.Close();
break;
case ((short)MSCommLib.OnCommConstants.comEvCD):
if (!axMSComm1.CDHolding)
{
richTextBox1.Clear();
richTextBox1.AppendText("Hanging up...");
try
{
axMSComm1.Output = "+++\r\n";
}
catch (Exception e11)
{
richTextBox1.AppendText(e11.ToString());
}
try
{
axMSComm1.Output = "ATH0\r\n";
}
catch (Exception e12)
{
richTextBox1.AppendText(e12.ToString());
}
richTextBox1.AppendText("Disconnected.");
}
break;
}
}
Best regards.
|
|
|
|
|
Hi,
Reposting is bad, but problem is urgent. Sorry for that !
I have a Web Application which referes to COM components for various reasons.
These COM components are built in VB6 and works fine when executed from Windows application from my machine.
This means, COM components are properly registered on my machine. When I gave reference to these from my Web App, respective Interop. DLL are created.
The COM component is the described as - "Microsoft VBUpgrade Tool TypeLib Visual Basic runtime objects and procedures" in VS.NET 2008 reference properties.
Question : I am getting following error when I try to create an object of VBRUN.PropertyBagClass
Error Message : An exception of type System.Runtime.InteropServices.COMException was raised and caught.<br />
Message: Retrieving the COM class factory for component with CLSID {D5DE8D20-5176-4EF2-8581-7B534D2AC56E} failed due to the following error: 80040154.
Stack Trace pointed to the line where object was being created
I searched google and came to a conclusion that I need to give rights of COM component execution for ASPNET account. I tried DCOM Configuration but am not sure to whom give the access rights and of what ?
It would be great if you guys give some sort of pointer to this ? Also wanted to make sure that my conclusion is right ?
Thanks !
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
hi
I have some prom problem with spliting mp3 file.
how can i split this type of file that work properly after spliting ?
I Want Learn
|
|
|
|
|
You need to write headers in both halves. It's best to use DirectX for this, not do it manually.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Search BinaryReader and BinaryWriter in MSDN.
I Love KongFu~
|
|
|
|
|
when a method is called i want to get first index value from an arraylist and when the same method is called next time i want to get the second index value from the same arraylist...how can i do that?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace roseapp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public ArrayList MPN = new ArrayList();
public string[,] Modems = new string[,]
{
{"Apple", "Banana", "81563840", "Damson"},
{"Elderberry", "Fig", "81547907", "Huckleberry"},
{"Indian Prune", "Jujube", "98764343322", "Lime"}
};
public string arrayValue;
private void button1_Click_1(object sender, EventArgs e)
{
// getphnum();
RoundRobin();
}
private int z = 0;
public void RoundRobin()
{
if (Modems == null)
throw new ArgumentNullException("Modem");
if (Modems.Length < 0)
return;
//int Count = 0;
int i;
int x = Modems.Length/4;
MessageBox.Show(Convert.ToString(x));
for (i = 0; i < x; i++)
{
string a = Modems[i, 2];
MessageBox.Show(a);
arrayValue = a;
MPN.Add(arrayValue);
}
for (int a = 0; a < MPN.Count; a++)
{
MessageBox.Show("ARRAY VALUE for index "+a+" "+Convert.ToString(MPN[a]));
}
}
public void getphnum()
{
z++;
MessageBox.Show(Convert.ToString(z));
}
}
}
in this when the getphnum() is called one time i wnat to get firts index value(ie index 0 ph number)ie MPN arraylist.ANd when next time when getphnum () is called i want to get index 1 value from arraylist MPN.(ie the same arraylist from which i call my first array index value)..
can somebody help meeeeeeeeeeee
|
|
|
|
|
Take a static class variable and initialize it with the index of array and when you call the method again just add 1 to that variable i.e use that variable like a counter hope this helps sorry for the bad english.
If thats not what you want then let me know
|
|
|
|
|
merryjoy000 wrote: in this when the getphnum() is called one time i wnat to get firts index value(ie index 0 ph number)ie MPN arraylist.ANd when next time when getphnum () is called i want to get index 1 value from arraylist MPN
Do you mean a counter? If yes, use "static“ for z var.
I Love KongFu~
|
|
|
|
|
I want to create tablelayoutpanel at runtime ..and this functionality same like how this control is doing at design time..like control moving and rows and Columns resizing..How these control is working at design time same like i need to create at runtime.
please any body know about this please tell me..
Thanks....
|
|
|
|
|
Create an object to TableLayoutPanel class and add it to your form. Go through the documentation to know what all properties are available. Set them and you are done.
The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures."
जय हिंद
|
|
|
|
|
Hi,
All controls are created at run time and the code for controls that are "designed" within VS resides in the InitializeComponent method of the Form.designer.cs file.
If you are not certain how to write code for a control then just create a test form using the control you want to learn about. Open up the designer.cs file and all will be revealed. The code you would write yourself will be very similar.
Alan.
|
|
|
|
|
i have 2 classes, i want to call a string from one method within a class to another class.
class SMSManager
{
public string abc;
public void testMethod(string MPN, string RPN, string text)
{
SMSModem SMSMdm = new SMSModem();
MessageBox.Show("RPN" + RPN);
abc = RPN;
int x = myArray.Length / 5;
for (int i = 0; i < x; i++)
{
string a = myArray[i, 0];
if (a == MPN)
{
MessageBox.Show("MODEM NUMBER :"+MPN);
SMSModem SMSM = new SMSModem();
SMSM.SendSms();
}
}
}
class SMSModem
{
public bool SendSms()
{
try
{
SMSManager MGR = new SMSManager();
string num = MGR.abc;
MessageBox.Show("RECEIRE" +num);
serialPort1.WriteLine("AT+CMGF=1;+CSCA=\"+6598540020\";+CMGS=\"+65" + num + "\"\r\n");
System.Threading.Thread.Sleep(40);
serialPort1.Write("Test message from coded program");
char[] arr = new char[1];
arr[0] = (char)26;
serialPort1.Write(arr, 0, 1);
System.Threading.Thread.Sleep(3000);
string data = serialPort1.ReadExisting();
MessageBox.Show(data);
if (data.IndexOf("OK") != -1)
{
return true;
}
else
{
return false;
}
}
catch
{
return false;
}
}
}
|
|
|
|
|
MSManager MGR = new SMSManager();
string num = MGR.abc;
MessageBox.Show("RECEIRE" +num);
string num = MGR.abc; before you can do this you need to call MGR.testMethod which actually does abc = RPN;
Alternatively
You can set the abc in a constructor.
Regards,
Karmendra
|
|
|
|
|
i call the MGR.testMethod in the button event in another form as:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void sampleArray()
{
}
private void button1_Click(object sender, EventArgs e)
{
SMSManager sm = new SMSManager();
sm.testMethod("82083427", "1122887779", "testmessagetxt");
}
}
how can i retreive the value then??
|
|
|
|
|
Think you need to re-visit OOPS concepts.
In button click event you have created another object sm and you have set sm.abc by running testMethod.
and you have never run SMSMdm.testMethod to set SMSMdm.abc, it wil give error also because you have never initialized SMSMdm.abc.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SMSManager <big>sm</big> = new SMSManager();
}
public void sampleArray()
{
}
private void button1_Click(object sender, EventArgs e)
{
sm.testMethod("82083427", "1122887779", "testmessagetxt");
}
}
class SMSManager
{
public string abc="";
public void testMethod(string MPN, string RPN, string text)
{
SMSModem SMSMdm = new SMSModem();
MessageBox.Show("RPN" + RPN);
abc = RPN;
int x = myArray.Length / 5;
for (int i = 0; i < x; i++)
{
string a = myArray[i, 0];
if (a == MPN)
{
MessageBox.Show("MODEM NUMBER :"+MPN);
SMSModem SMSM = new SMSModem();
SMSM.SendSms();
}
}
}
class SMSModem
{
public bool SendSms()
{
try
{
string num = <big>sm</big>.abc;
MessageBox.Show("RECEIRE" +num);
serialPort1.WriteLine("AT+CMGF=1;+CSCA=\"+6598540020\";+CMGS=\"+65" + num + "\"\r\n");
System.Threading.Thread.Sleep(40);
serialPort1.Write("Test message from coded program");
char[] arr = new char[1];
arr[0] = (char)26;
serialPort1.Write(arr, 0, 1);
System.Threading.Thread.Sleep(3000);
string data = serialPort1.ReadExisting();
MessageBox.Show(data);
if (data.IndexOf("OK") != -1)
{
return true;
}
else
{
return false;
}
}
catch
{
return false;
}
}
}
Remember all these should be in same namespace.
Regards,
Karmendra
|
|
|
|
|
Aghosh Babu wrote: abc = RPN; //this isnt wrking
What do you mean it did not work? It is just a simple assign-op. Maybe you can debug it.
Aghosh Babu wrote: string num = MGR.abc; //This is not retreiving the value!//I WANT THAT VALUE TO BE CALLED HERE AND ASSIGN IT TO "num"
According to the cdoe, the value should be null.
I Love KongFu~
|
|
|
|
|
Hi,
I have created a login in my winform application, i encrypt the password and store in a xml file.
I am worried about if the user deletes the xml file, he can crack into the system.
can you please suggest me how to make sure user cannot delete the xml file.
I tried embedding the xml file but, if i do that authorized users will not be able to change password and update the xml.
Please help
Thanks for your time and knowledge,
Karmendra
|
|
|
|
|
KSuthar wrote: if the user deletes the xml file, he can crack into the system.
Why? If the application can not validate the password by using your xml file, in other words, the validation fails. In this case, the app should not let the user login. Hence, it should not be the problem at all.
I Love KongFu~
|
|
|
|
|
And if the user deletes the xml file by going to the physical location of the file. what shall I do in such case. as of now my program recreates the xml with default password.
|
|
|
|
|
KSuthar wrote: And if the user deletes the xml file by going to the physical location of the file. what shall I do in such case. as of now my program recreates the xml with default password.
That's entirely up to you and your app specifications how it should respond. Recreating with a default password seems reasonable, IF it doesn't compromise the secruity of your data.
Oh! You can't stop someone from deleting the file...
|
|
|
|
|
KSuthar wrote: what shall I do in such case.
If the user has the administration authority, I do not think we can stop him/her to delete the file. Maybe you can design you app logic again for validating password.
KSuthar wrote: as of now my program recreates the xml with default password.
Is it safe enough for you? If yes, go ahead.
I Love KongFu~
|
|
|
|
|
Hello everyone,
Here is my code at both client side and server side. My code is simple, just upload a file to an ASP.Net web site.
My client code throws exception when it works on Vista (x64, Enterprise, SP1), but works fine on Windows Server 2003.
Any ideas?
10.10.12.162 is my server address.
Client:
static void Main(string[] args)
{
Console.Write("\nPlease enter the URI to post data to : ");
String uriString = Console.ReadLine();
WebClient myWebClient = new WebClient();
Console.WriteLine("\nPlease enter the fully qualified path of the file to be uploaded to the URI");
string fileName = Console.ReadLine();
Console.WriteLine("Uploading {0} to {1} ...", fileName, uriString);
DateTime begin = DateTime.Now;
byte[] responseArray = null;
try
{
responseArray = myWebClient.UploadFile(uriString, fileName);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.ToString());
}
DateTime end = DateTime.Now;
Console.WriteLine("Elapsed time is: {0}", (end - begin).TotalMilliseconds);
}
Server:
public partial class FileUploadHandler : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
foreach (string f in Request.Files.AllKeys)
{
HttpPostedFile file = Request.Files[f];
file.SaveAs("D:\\UploadFile\\UploadedFiles\\" + file.FileName);
}
}
}
Exception from client side:
Unable to connect to the remote server
System.Net.WebException: Unable to connect to the remote server ---> System.Net.
Sockets.SocketException: No connection could be made because the target machine
actively refused it 10.10.12.162:1031
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddre
ss socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Sock
et s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state,
IAsyncResult asyncResult, Int32 timeout, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.WebClient.UploadFile(Uri address, String method, String fileNam
e)
at FileUploadClient.Program.Main(String[] args) in D:\UploadFile\FileUploadClient\Program.cs:line 30
regards,
George
|
|
|
|