Can't use Optimization functions with ilnumerics in c# - c#

If I am right, there is a optimization toolbox in ilnumerics. After I successfully installed ilnumerics in my project I tried to write some examples from http://ilnumerics.net/media/ILNumericsOptimizationToolboxDocumentation.pdf in it. However anytime i use * = Optimization.* there is an error, like "Optimization" is an undefinded variable. "The name 'Optimization' does not exist in the current context"
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 ILNumerics;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
class Program : ILMath
{
public static ILRetArray<double> MeyerFunc(ILInArray<double> x, ILInArray<double> t)
{
using (ILScope.Enter(x, t))
{
return x[0] * exp(x[1] / (t + x[2]));
}
}
//The computation of the minimum is done as follows:
// Minimum computation:
ILArray<double> t = linspace<double>(0, 15, 16).T;
ILArray<double> ydata = array<double>(34780.0, 28610.0, 23650.0, 19630.0, 16370.0,
13720.0, 11540.0, 9744.0, 8261.0, 7030.0,
6005.0, 5147.0, 4427.0, 3820.0, 3307.0, 2872.0);
ILArray<double> x0 = array<double>(1.0, 200.0, 100.0);
Func<ILInArray<double>, ILRetArray<double>> meyerfunction = x =>
{
using (ILScope.Enter(x))
{
return MeyerFunc(x, t);
}
};
ILArray<double> xm = Optimization.optimpdl(meyerfunction, x0, ydata);
}
}

The line
ILArray<double> xopt = Optimization.optimpdl(objfunc, zeros<double>(2, 1));
is supposed to be inside the main function, not after and outside of it.

Related

UI TestStack White Get Value from a DataCell

Does anyone know how to get Vlaue from a ""DataCell(DataGridViewTextBoxCell)"?
I need to get a value from DataCell using its "Name" = "Symbol Row 0" or "RuntimeId" = "42 1966418 3 1 0"".
My current code is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestStack.White;
using TestStack.White.Factory;
using TestStack.White.UIItems;
using TestStack.White.UIItems.Finders;
using TestStack.White.UIItems.WindowItems;
namespace UI_006
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(System.Diagnostics.Process.GetProcessesByName("program1")[0].Id);
Application application = TestStack.White.Application.Attach(System.Diagnostics.Process.GetProcessesByName("program1")[0].Id);
Window Calcwindow = application.GetWindow(SearchCriteria.ByText("toto"), InitializeOption.NoCache);
application.WaitWhileBusy();
}
}
}
My UISpy SceenShot:

C# pointer with offset and vaMemory.dll

So I want to try to read a value from memory using a pointer with 1 offset.
These are my value:
I tried to write some code but it does not work. It only ever reads value 0 but I see on cheat engine the value i is different.
Below is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Trigger
{
class Program
{
static void Main(string[] args)
{
VAMemory vam = new VAMemory("test");
int LocalPlayer = vam.ReadInt32((IntPtr)0x01608310);
while (true) {
int address = LocalPlayer + 0x360;
Console.Write(vam.ReadInt32((IntPtr)address));
//Thread.sleep(500);
}
}
}
}
So can someone help me to understand?

Synaptics SDK can't find device

I'm attempting to grab a device handle on the Synaptics Touchpad using the Synaptics SDK, specifically using methods in the SYNCTRLLib.
However, the SYNCTRL method failed to find it, returning -1.
Syn.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SYNCOMLib;
using SYNCTRLLib;
namespace TP_Test1
{
class Syn
{
SynAPICtrl SynTP_API = new SynAPICtrl();
SynDeviceCtrl SynTP_Dev = new SynDeviceCtrl();
SynPacketCtrl SynTP_Pack = new SynPacketCtrl();
int DeviceHandle;
//Constructor
public Syn ()
{
SynTP_API.Initialize();
SynTP_API.Activate();
//DeviceHandle == -1 ? Can't find device?
DeviceHandle = SynTP_API.FindDevice(new SynConnectionType(), new SynDeviceType(), 0);
//Below line causing Unhandled Exception
SynTP_Dev.Select(DeviceHandle);
SynTP_Dev.Activate();
SynTP_Dev.OnPacket += SynTP_Dev_OnPacket;
}
public void SynTP_Dev_OnPacket()
{
Console.WriteLine(SynTP_Pack.FingerState);
Console.WriteLine(SynTP_Pack.X);
Console.WriteLine(SynTP_Pack.Y);
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SYNCOMLib;
using SYNCTRLLib;
namespace TP_Test1
{
class Program
{
static void Main(string[] args)
{
Syn mySyn = new Syn();
mySyn.SynTP_Dev_OnPacket();
}
}
}
I see that you are using the C# wrappers for Synaptics SDK. Even though CPP code might be not trivial to you, you might want to take a look at the file Samples/ComTest.cpp. It contains some example logic in order to find devices, more specifically at lines 66-76:
// Find a device, preferentially a TouchPad or Styk.
ISynDevice *pDevice = 0;
long lHandle = -1;
if ((pAPI->FindDevice(SE_ConnectionAny, SE_DeviceTouchPad, &lHandle) &&
pAPI->FindDevice(SE_ConnectionAny, SE_DeviceStyk, &lHandle) &&
pAPI->FindDevice(SE_ConnectionAny, SE_DeviceAny, &lHandle)) ||
pAPI->CreateDevice(lHandle, &pDevice))
{
printf("Unable to find a Synaptics Device.\n");
exit(-1);
}
Also, make sure you have registered the dlls. According to the ReadSynSDK.txt file:
For certain purposes it may be necessary to register the dlls
that are provided with the SDK. This can be done with the windows regsvr32
utility.

Create images from PDF file pages in C#

I want to get images from PDF file pages. I know that a good solution is to use ghostscriptsharp. It has a special method to get a single page or multiple pages.
GeneratePageThumbs(string inputPath, string outputPath, int firstPage, int lastPage, int width, int height)
Here is my complete code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GhostscriptSharp;
namespace GetPages
{
class Program
{
static void Main(string[] args)
{
GhostscriptWrapper.GeneratePageThumbs(#"C:\Users\User\Downloads\English_Medium_Extra_for_WEB-2.pdf",
#"C:\Users\User\Desktop\Test", 1, 3, 130, 130);
}
}
}
But when I use this method I have exception.
ExternalException
Ghostscript conversion error
So i fix this!The problem lies in the fact that 2 parameter should be the name of your image you get as a result, not a path where to save the image!
Here is the code works correctly:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GhostscriptSharp;
namespace GetPages
{
class Program
{
static void Main(string[] args)
{
GhostscriptWrapper.GeneratePageThumbs(#"C:\Users\User\Downloads\English_Medium_Extra_for_WEB-2.pdf",
"Example.png", 1, 3, 130, 130);
}
}
}
Thank you!Question is closed.
replace "Example.png" by "Example%d.png" to get all 3 Pages.

C# and Microsoft Speech.Recognition and Speech.Synthesis

I'm new to C# and I'm new to Speech.Recognition.
I searched very long for tutorials but didn't find that much, I'm even not quiet sure whether I included everything correctly.
I downloaded:
SDK
Runtime
Languages
I'm programming local, I have Windows XP, .net framework 3.5.
Now I just want to get started with some simple lines of code, like to say "hello world" or say one or two words as input.
I tried following, and of course it doesn't work :>
error:
"The Typ- or Namespacename "SpeechSynthesizer" couldn't be found (Is a Using-Direktive or a Assemblyverweis missing?)"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
namespace System.Speech.Recognition { }
namespace System.Speech.AudioFormat {}
namespace System.Speech.Recognition.SrgsGrammar{}
namespace System.Speech.Synthesis { }
namespace System.Speech.Synthesis.TtsEngine { }
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SpeechSynthesizer foo = new SpeechSynthesizer();
foo.Speak("Test");
}
}
}
edit:
hello,
i tried you code,but
using SpeechLib;
couldn't be found :>
well now i wrote:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.SpeechLib;
namespace System.SpeechLib { }
namespace System.Speech.Recognition { }
namespace System.Speech.AudioFormat {}
namespace System.Speech.Recognition.SrgsGrammar{}
namespace System.Speech.Synthesis { }
namespace System.Speech.Synthesis.TtsEngine { }
but I get an error with:
numericUpDown1,SpVoice,SpeechVoiceSpeakFlags,textBox1 and Timeout
Project + Add Reference, .NET tab, select "System.Speech".
A project template pre-selects several .NET assemblies. But only common ones, like System.dll, System.Core.dll, etcetera. You have to add the 'unusual' ones yourself.
you can try this:
get Interop.SpeechLib.dll
using SpeechLib;
private void ReadText(string readText)
{
int iCounter = 0;
while (Convert.ToInt32(numericUpDown1.Value) > iCounter)
{
SpVoice spVoice = new SpVoice();
spVoice.Speak(textBox1.Text, SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
spVoice.WaitUntilDone(Timeout.Infinite);
iCounter = iCounter + 1;
}
}

Categories