/// <summary> /// 現在のPHANTOM手先速度を返します /// </summary> /// <returns>速度ベクトル [mm/s]</returns> public Vector3 GetVelocity() { double[] velocity = new double[3] { 0, 0, 0 }; Hd.hdGetDoublev(Hd.ParameterName.HD_CURRENT_VELOCITY, velocity); return(new Vector3((float)velocity[0], (float)velocity[1], -(float)velocity[2])); }
/// <summary> /// PHANTOM発揮力を設定します /// </summary> /// <param name="force">力のベクトル [N]</param> public void SetForce(Vector3 force) { double[] forceArray = new double[3]; forceArray[0] = force.x; forceArray[1] = force.y; forceArray[2] = -force.z; Hd.hdSetDoublev(Hd.ParameterName.HD_CURRENT_FORCE, forceArray); }
/// <summary> /// 現在のPHANTOM手先座標を返します /// </summary> /// <returns>ジンバル座標 [mm]</returns> public Vector3 GetPosition() { double[] position = new double[3] { 0, 0, 0 }; Hd.hdGetDoublev(Hd.ParameterName.HD_CURRENT_POSITION, position); return(new Vector3((float)position[0], (float)position[1], -(float)position[2])); }
public void GenerateRandomKeys() { var keys = Hd.BuildKey(); var wallet = keys.ToWallet(); _testOutputHelper.WriteLine(keys.PrivateKey.ToHex()); _testOutputHelper.WriteLine(wallet.Base58Address); }
/// <summary> /// 同期的に処理を呼び出します /// </summary> public void Do(Callback callback) { Hd.hdScheduleSynchronous( (data) => { return(DoCallback(callback)); }, IntPtr.Zero, Hd.Priority.HD_DEFAULT_SCHEDULER_PRIORITY ); ErrorCheck("ScheduleSynchronous"); }
public void CreateWalletFromSeed(string seed, int deriveIndex, string address) { var keys = new Hd(seed, deriveIndex); _testOutputHelper.WriteLine(keys.PublicKey.ToHex()); var wallet = keys.ToWallet(); Assert.Equal(address, wallet.Base58Address); }
public void CreateWallet(string pk, string address) { var keys = Hd.FromPrivateKey(pk); _testOutputHelper.WriteLine(keys.PublicKey.ToHex()); var wallet = keys.ToWallet(); Assert.Equal(address, wallet.Base58Address); }
public async Task GetTxHashesByWalletAddress() { var client = new Client(Url); var hd = Hd.FromPrivateKey(Pk); var hashes = await client.Tx.GetHashListByAddress(hd.ToWallet().Base58Address); Assert.NotEmpty(hashes); _testOutputHelper.WriteLine(hashes[0]); }
/// <summary> /// </summary> /// <param name="unspents"></param> /// <param name="amount"></param> /// <param name="key"></param> /// <param name="fromAddress"></param> /// <param name="to"></param> /// <param name="commission"></param> public Transaction(PreviousOutput[] unspents, ulong amount, Hd key, string fromAddress, string to, ulong commission) { ulong totalin = 0; foreach (var previousOutput in unspents) { totalin += previousOutput.Value; } var index = 0; TxIns = new List <TxIn>(); // Comission TxOuts = new List <TxOut>(); TxOuts.Add(new TxOut { Index = index++, PublicKeyScript = "", Value = commission }); // Dest address TxOuts.Add(new TxOut { Index = index++, PublicKeyScript = Base58.Bitcoin.Decode(to).ToArray().ToHex(), Value = amount }); var change = totalin - amount - commission; if (change > 0) { // My address TxOuts.Add(new TxOut { Index = index, PublicKeyScript = Base58.Bitcoin.Decode(fromAddress).ToArray().ToHex(), Value = change }); } foreach (var previousOutput in unspents) { var sigMsg = MsgForSign(previousOutput.Hash, previousOutput.Index); var sig = PublicKeyAuth.SignDetached(sigMsg, key.PrivateKey); TxIns.Add(new TxIn { PublicKey = key.PublicKey, Sequence = 1, PreviousOutput = previousOutput, SigScript = sig.ToHex() }); } }
public async Task GetUnspents() { var client = new Client(Url); var keys = Hd.FromPrivateKey(Pk); var wallet = keys.ToWallet(); var unspents = await client.Wallet.GetUnspent(wallet.Base58Address); Assert.NotEmpty(unspents); _testOutputHelper.WriteLine(unspents[0].Hash); }
public async Task GetWalletBalance() { var client = new Client(Url); var keys = Hd.FromPrivateKey(Pk); var wallet = keys.ToWallet(); var balance = await client.Wallet.GetBalance(wallet.Base58Address); Assert.NotEqual <ulong>(0, balance); _testOutputHelper.WriteLine(balance.ToString()); }
/// <summary> /// 登録済の非同期実行処理を全て消去します /// </summary> public void ClearSchedule() { foreach (uint handle in ScheduleHandles) { Hd.hdUnschedule(handle); ErrorCheck("Unschedule #" + handle.ToString()); } ScheduleHandles.Clear(); CallbackMethods.Clear(); }
/// <summary> /// デバイスの使用を終了し、切断します /// </summary> public void Close() { Stop(); ClearSchedule(); if (hHD != (uint)Hd.DeviceHandle.HD_INVALID_HANDLE) { Hd.hdDisableDevice(hHD); ErrorCheck(); } }
// ↓たぶん誰も使わないし、Unity座標系への変換をしていないのでコメントアウト // /// <summary> // /// 現在のPHANTOMジンバル姿勢を返します // /// <remarks>手先の姿勢ではありません。ジンバル部エンコーダの値です。</remarks> // /// </summary> // /// <returns>ジンバル部分の内、根元からペン部にかけて X~Z に対応した角度 [rad]</returns> // public Vector3 GetGimbalAngles() // { // double[] gimbals = new double[3] { 0, 0, 0 }; // Hd.hdGetDoublev(Hd.ParameterName.HD_CURRENT_GIMBAL_ANGLES, gimbals); // return new Vector3((float)gimbals[0], (float)gimbals[1], (float)gimbals[2]); // } /// <summary> /// 現在のPHANTOM手先姿勢を返します /// </summary> /// <returns>姿勢を表すクォータニオン</returns> public Quaternion GetRotation() { double[] matrix = new double[16]; Hd.hdGetDoublev(Hd.ParameterName.HD_CURRENT_TRANSFORM, matrix); double qw = Math.Sqrt(1f + matrix[0] + matrix[5] + matrix[10]) / 2; double w = 4 * qw; double qx = (matrix[6] - matrix[9]) / w; double qy = (matrix[8] - matrix[2]) / w; double qz = (matrix[1] - matrix[4]) / w; return(new Quaternion((float)-qx, (float)-qy, (float)qz, (float)qw)); }
/// <summary> /// 直前のHDAPI呼び出しでエラーがあれば、例外を発生させます /// </summary> private void ErrorCheck() { Hd.ErrorInfo error; if (Hd.IsError(error = Hd.hdGetError())) { string message = Hd.GetErrorString(error.ErrorCode); Debug.LogError("HDAPI error : " + message); //throw new UnityException("SimplePhantom : " + message); } }
/// <summary> /// コールバックメソッド呼び出しをより簡略化するためのラップ /// </summary> /// <param name="callback">引数無しでboolを返すだけに簡略化したメソッド</param> /// <returns>完了したか</returns> private Hd.CallbackResult DoCallback(Callback callback) { bool result; Hd.hdBeginFrame(hHD); ErrorCheck("BeginFrame"); result = callback(); Hd.hdEndFrame(hHD); ErrorCheck("EndFrame"); return(result ? Hd.CallbackResult.HD_CALLBACK_CONTINUE : Hd.CallbackResult.HD_CALLBACK_DONE); }
/// <summary> /// 非同期処理を停止します /// </summary> public void Stop() { if (!IsRunning) { return; } Hd.hdStopScheduler(); ErrorCheck(); // 力も停止 Hd.hdDisable(Hd.Capability.HD_FORCE_OUTPUT); ErrorCheck(); IsRunning = false; }
public ActionResult create(Hd hd, IEnumerable <Cthd> lstcthd) { try { TaiKhoan tk = (TaiKhoan)Session["USER_SESSION"]; HoaDonManger.insert(hd); SanPham sp; Hd item = HoaDonManger.GetItemById(hd.MaHD); KhachHang kh = KhachHangMager.GetKhachHangByID(hd.MaKH); if (kh != null) { decimal?thanhtien; foreach (var x in lstcthd) { sp = SanPhamMager.GetSanPhamByID(x.MaSp); if (x.SoLuong < sp.SoLuongTon) { sp.SoLuongTon = sp.SoLuongTon - x.SoLuong; SanPhamMager.tinhgiaban(x.MaSp); SanPhamMager.uppdateSanPham(sp); x.MaHD = item.MaHD; x.TenSP = sp.TenSp; x.DonGiaBan = sp.DonGiaBan; thanhtien = x.SoLuong * x.DonGiaBan * (decimal)0.1; kh.Diemso = kh.Diemso + (int)thanhtien; KhachHangMager.uppdateKhachHang(kh); } } } CTHDMager.insertall(lstcthd); KhachHangMager.checkpointKH(kh.MaKh); return(RedirectToAction("Index")); } catch { TaiKhoan tk = (TaiKhoan)Session["USER_SESSION"]; List <SanPham> lst = SanPhamMager.getAllSanPham(); List <KhachHang> lstkh = KhachHangMager.GetAllKhachHang(); ViewBag.khachhang = lstkh; ViewBag.sanpham = new SelectList(lst, "Masp", "TenSp"); ViewBag.nhanvien = TaiKhoanMager.getNVbytk(tk.MaTK); return(View()); } }
/// <summary> /// デフォルトのデバイスに接続します /// </summary> public SimplePhantomUnity() { IsRunning = false; // デフォルトのデバイスを準備 hHD = Hd.hdInitDevice(Hd.DeviceHandle.HD_DEFAULT_DEVICE); ErrorCheck("Initialize device"); // コールバックメソッドを保持するリスト CallbackMethods = new List <Hd.SchedulerCallback>(); // スケジューリングされたメソッドのハンドルをこれで保持 ScheduleHandles = new List <ulong>(); // 可動範囲を取得 LoadWorkspaceLimit(); }
/// <summary> /// ペン先端の座標を返します /// </summary> /// <returns>ペン先端座標 [mm]</returns> public Vector3 GetTipPosition() { double[] position = new double[3] { 0, 0, 0 }; double[] matrix = new double[16]; Hd.hdGetDoublev(Hd.ParameterName.HD_CURRENT_POSITION, position); Hd.hdGetDoublev(Hd.ParameterName.HD_CURRENT_TRANSFORM, matrix); Vector3 tipPosition; tipPosition.x = (float)(position[0] + matrix[0] * TipOffset.x + matrix[4] * TipOffset.y + matrix[8] * TipOffset.z); tipPosition.y = (float)(position[1] + matrix[1] * TipOffset.x + matrix[5] * TipOffset.y + matrix[9] * TipOffset.z); tipPosition.z = -(float)(position[2] + matrix[2] * TipOffset.x + matrix[6] * TipOffset.y + matrix[10] * TipOffset.z); return(tipPosition); }
/// <summary> /// 非同期処理を開始します /// </summary> public void Start() { if (IsRunning) { return; } // 力を発生させるのは標準でON Hd.hdEnable(Hd.Capability.HD_FORCE_OUTPUT); ErrorCheck(); // 非同期処理も開始 Hd.hdStartScheduler(); ErrorCheck(); IsRunning = true; }
/// <summary> /// 非同期実行にメソッドを追加します /// </summary> /// <param name="callback">要継続ならtrueを返すコールバックメソッド</param> public void AddSchedule(Callback callback) { Hd.SchedulerCallback method = (data) => { return(DoCallback(callback)); }; CallbackMethods.Add(method); ulong handle = Hd.hdScheduleAsynchronous( method, IntPtr.Zero, Hd.Priority.HD_DEFAULT_SCHEDULER_PRIORITY ); ErrorCheck("ScheduleAsynchronous"); ScheduleHandles.Add(handle); }
/// <summary> /// 非同期処理を開始します /// </summary> public void Start() { if (!IsAvailable || IsRunning) { return; } // 力を発生させるのは標準でON Hd.hdEnable(Hd.Capability.HD_FORCE_OUTPUT); ErrorCheck("Enable force output"); // 非同期処理も開始 Hd.hdStartScheduler(); ErrorCheck("Start scheduler"); IsRunning = true; }
/// <summary> /// 直前のHDAPI呼び出しでエラーがあれば、例外を発生させます /// </summary> /// <param name="situation">何をしていたかを伝える文字列</param> static private void ErrorCheck(string situation) { Hd.ErrorInfo error; if (Hd.IsError(error = Hd.hdGetError())) { string errorMessage = Hd.GetErrorString(error.ErrorCode); if (situation.Equals("")) { throw new UnityException("HDAPI : " + errorMessage); } else { throw new UnityException(situation + " / HDAPI : " + errorMessage); } } }
public async Task ValidateTx() { var keys = Hd.FromPrivateKey(Pk); var wallet = keys.ToWallet(); var client = new Client(Url); var unspents = await client.Wallet.GetUnspent(wallet.Base58Address); var tx = new Transaction( unspents, 1000, keys, wallet.Base58Address, "VLa1hi77ZXD2BSWDD9wQe8vAhejXyS7vBM4", 1000000 ).Sign(); var result = await client.Tx.Validate(tx); Assert.Equal("ok", result); _testOutputHelper.WriteLine(result); }
/// <summary> /// 可動範囲を取得 /// </summary> private void LoadWorkspaceLimit() { double[] val = new double[6]; // 可動限界範囲を取得 Hd.hdGetDoublev(Hd.ParameterName.HD_MAX_WORKSPACE_DIMENSIONS, val); ErrorCheck("Getting max workspace"); WorkspaceMinimum = new Vector3((float)val[0], (float)val[1], -(float)val[2]); WorkspaceMaximum = new Vector3((float)val[3], (float)val[4], -(float)val[5]); // 推奨可動範囲を取得 Hd.hdGetDoublev(Hd.ParameterName.HD_USABLE_WORKSPACE_DIMENSIONS, val); ErrorCheck("Getting usable workspace"); UsableWorkspaceMinimum = new Vector3((float)val[0], (float)val[1], -(float)val[2]); UsableWorkspaceMaximum = new Vector3((float)val[3], (float)val[4], -(float)val[5]); // 机の高さを取得 float[] offset = new float[1]; Hd.hdGetFloatv(Hd.ParameterName.HD_TABLETOP_OFFSET, offset); ErrorCheck("Getting table-top offset"); TableTopOffset = (float)offset[0]; }
/// <summary> /// 非同期処理を停止します /// </summary> public void Stop() { if (!IsAvailable || !IsRunning) { return; } IsRunning = false; ////System.Threading.Thread.Sleep (10); //foreach (uint handle in ScheduleHandles) //{ // Hd.hdWaitForCompletion(handle, Hd.WaiteCode.HD_WAIT_INFINITE); // ErrorCheck("Waiting for completion"); //} Hd.hdStopScheduler(); ErrorCheck("StopScheduler"); // 力も停止 Hd.hdDisable(Hd.Capability.HD_FORCE_OUTPUT); ErrorCheck("Disable force output"); }
/*private void btnLoc_Click(object sender, EventArgs e) * { * try * { * int d1 = System.Convert.ToInt32(DateStart.Text); * int d2 = System.Convert.ToInt32(DateEnd.Text); * int m1 = System.Convert.ToInt32(mothStart.Text); * int m2 = System.Convert.ToInt32(monthEnd.Text); * int y1 = System.Convert.ToInt32(yearStart.Text); * int y2 = System.Convert.ToInt32(yearEnd.Text); * * DateTime dateFrom = new DateTime(y1, m1, d1); * DateTime dateTo = new DateTime(y2, m2, d2); * * if (dateTo.CompareTo(dateFrom) > 0) * { * Data.DataSource = from s in db.Sds * from h in db.Hds * from k in db.Khs * from _s in db.Sims * where s.TgBd.Value.CompareTo(dateFrom)>=0 * && s.TgKt.Value.CompareTo(dateTo)<=0 && k.MaKh == h.MaKh * select new * { * ID = s.MaSd, * NumberPhone = _s.SoSim, * Customer = k.TenKh, * Buildday = h.Ngaylap, * Payday = h.Ngaytra, * Time = s.TgKt - s.TgBd, * Total = s.TongTien * }; * } * else * { * MessageBox.Show("Kiểm tra lại dữ liệu nhập"); * } * } * catch(Exception ex) * { * Console.WriteLine(ex.Message); * } * }*/ private void button2_Click(object sender, EventArgs e) { try { if (Data.SelectedCells[0].OwningRow.Cells["Status"].FormattedValue.ToString() == "Đã thanh toán") { MessageBox.Show("Đã cập nhật rồi"); } else { //Hd hd = new db.Hds.Where(p => p.SoSim.Equals(cbxSosim.Text)).SingleOrDefault(); int a = System.Convert.ToInt32(Data.SelectedCells[0].OwningRow.Cells["ID"].FormattedValue.ToString()); Hd h = db.Hds.Where(p => p.MaHd.Equals(a)).SingleOrDefault(); h.TrangThai = true; db.SubmitChanges(); MessageBox.Show("Cập nhật thành công!"); LayDanhSach(); } } catch { MessageBox.Show("Lỗi!"); } }
public static Hd insert(Hd item) { return(new HdController().Insert(item)); }
public static Hd uppdate(Hd item) { return(new HdController().Update(item)); }